diff --git a/internal/browser/pyproject/baskets/service.py b/internal/browser/pyproject/baskets/service.py index 6443649..6385a45 100644 --- a/internal/browser/pyproject/baskets/service.py +++ b/internal/browser/pyproject/baskets/service.py @@ -141,3 +141,19 @@ def complete_basket(self, basket): basket.save() return basket + + def _create_quotation_items(self, quotation: Quotation | Order, basket_items: list[BasketItem]) -> None: + QuotationItem.objects.bulk_create( + [ + QuotationItem( + quotation=quotation, + product_remote_id=bi.product_remote_id, + quantity=bi.quantity, + division=bi.division, + price=bi.price, + data=bi.data, + currency=bi.currency, + ) + for bi in basket_items + ] + ) diff --git a/internal/browser/python.go b/internal/browser/python.go index f01ffc5..4715f51 100644 --- a/internal/browser/python.go +++ b/internal/browser/python.go @@ -125,7 +125,7 @@ func (b *PythonBrowser) findFunctions(fileContent string) map[string]string { functions := make(map[string]string) lines := strings.Split(fileContent, "\n") - functionRegex := regexp.MustCompile(`^\s*def\s+(\w+)\s*\((.*?)\):`) + functionRegex := regexp.MustCompile(`def\s+([a-zA-Z_]\w*)\s*\(([^)]*)\)\s*(?:->\s*([a-zA-Z_]\w*|\w*))?:`) var currentFunctionName string var currentFunctionContent string diff --git a/internal/browser/python_test.go b/internal/browser/python_test.go index fc98247..87f67a6 100644 --- a/internal/browser/python_test.go +++ b/internal/browser/python_test.go @@ -68,18 +68,19 @@ func TestPythonBrowser_ParseFile(t *testing.T) { assert.Equal(t, "/cars/exceptions.py", node.ImportRaw[7]) assert.Equal(t, "/cars", node.ImportRaw[8]) - assert.Equal(t, 143, node.LineCount) + assert.Equal(t, 159, node.LineCount) - assert.Equal(t, 8, len(node.Functions)) + assert.Equal(t, 9, len(node.Functions)) funcs := map[string]int{ - "get_or_create_basket": 16, - "apply_discounts": 15, - "_check_basket_items": 17, - "add_basket_item": 22, - "clean_discounts": 7, - "clean_basket": 7, - "delete_basket_item": 7, - "complete_basket": 19, + "get_or_create_basket": 16, + "apply_discounts": 15, + "_check_basket_items": 17, + "add_basket_item": 22, + "clean_discounts": 7, + "clean_basket": 7, + "delete_basket_item": 7, + "complete_basket": 19, + "_create_quotation_items": 14, } for _, f := range node.Functions { assert.Equal(t, funcs[f.Name], f.LineCount, f.Name)