From b3b74c1f69ba0b29aab6887d64f0ae216c411024 Mon Sep 17 00:00:00 2001 From: cosmos Date: Sat, 25 Jan 2025 11:33:24 -0500 Subject: [PATCH 01/13] Add brach 7.4, fields orde.line and xmls --- __init__.py | 1 + sale_order.py | 56 +++++++++++++++++++++++++++++++++++ sale_order.xml | 27 +++++++++++++++++ tests/scenario_sale_order.rst | 7 +++-- view/order_form.xml | 14 +++++++++ view/order_tree.xml | 7 +++++ 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 sale_order.xml create mode 100644 view/order_form.xml create mode 100644 view/order_tree.xml diff --git a/__init__.py b/__init__.py index 0ffc962..adfee55 100644 --- a/__init__.py +++ b/__init__.py @@ -7,6 +7,7 @@ __all__ = ['register'] def register(): Pool.register( sale_order.SaleOrder, + sale_order.OrderLine, module='sale_order', type_='model') Pool.register( module='sale_order', type_='wizard') diff --git a/sale_order.py b/sale_order.py index 0ce48ba..35f48f0 100644 --- a/sale_order.py +++ b/sale_order.py @@ -1,4 +1,10 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields +from trytond.modules.currency.fields import Monetary +from trytond.modules.product import price_digits +from trytond.pyson import Eval +from decimal import Decimal class SaleOrder(ModelView, ModelSQL): @@ -12,3 +18,53 @@ class SaleOrder(ModelView, ModelSQL): [("on_site", "On Site"), ("at_home", "At Home")], 'Pickup Location' ) + lines = fields.One2Many( + 'order.line', 'order', 'Lines' + ) + + +class OrderLine(ModelView, ModelSQL): + "Order Line" + __name__ = 'order.line' + + order = fields.Many2One( + 'sale.order', "Sale" + ) + product = fields.Many2One( + 'product.product', 'Product', required=True + ) + unit = fields.Many2One( + 'product.uom', 'Unit', + domain=[ + ('category', '=', Eval('product_uom_category')), + ], + depends=['product_uom_category'] + ) + product_uom_category = fields.Function( + fields.Many2One('product.uom.category', 'Product UOM Category'), + 'on_change_with_product_uom_category' + ) + quantity = fields.Float( + "Quantity", digits=('unit') + ) + unitprice = Monetary( + "Unit Price", digits=price_digits, currency='currency' + ) + total_amount = fields.Function( + Monetary("Total Amount", currency='currency', digits='currency'), + 'get_total_amount' + ) + + @fields.depends('product') + def on_change_with_product_uom_category(self, name=None): + if self.product: + return self.product.default_uom.category.id + return None + + @fields.depends('quantity', 'unitprice') + def on_change_with_total_amount(self): + total_amount = self.unitprice * Decimal(self.quantity) + return total_amount + + def get_total_amount(self): + return self.on_change_with_total_amount() diff --git a/sale_order.xml b/sale_order.xml new file mode 100644 index 0000000..961ff6b --- /dev/null +++ b/sale_order.xml @@ -0,0 +1,27 @@ + + + + + + sale.order + tree + order_tree + + + sale.order + form + order_form + + + order.line + tree + line_tree + + + order.line + form + line_form + + + diff --git a/tests/scenario_sale_order.rst b/tests/scenario_sale_order.rst index 1d5e872..be50dca 100644 --- a/tests/scenario_sale_order.rst +++ b/tests/scenario_sale_order.rst @@ -37,8 +37,9 @@ Create order:: >>> order.save() >>> line1 = order.lines.new() >>> line1.product = product - >>> line1.quantity = 4 - >>> line1.unitprice = 8400 - >>> line1.total_amount = 33600 + >>> line1.unit = unit + >>> line1.quantity = 4.0 + >>> line1.unitprice = Decimal('8400') + >>> line1.total_amount = Decimal('33600') >>> order.save() \ No newline at end of file diff --git a/view/order_form.xml b/view/order_form.xml new file mode 100644 index 0000000..f228a57 --- /dev/null +++ b/view/order_form.xml @@ -0,0 +1,14 @@ + + +
+