diff --git a/app_product_weight_sale/__manifest__.py b/app_product_weight_sale/__manifest__.py index 529f8c76..f6bac0b3 100644 --- a/app_product_weight_sale/__manifest__.py +++ b/app_product_weight_sale/__manifest__.py @@ -3,13 +3,14 @@ { 'name': 'App Product Weight in Sales Order', - 'version': '12.0.11.26', - 'summary': 'Add Product sku weight in Sale Order, product weight, sale weight, total weight', + 'version': '12.19.01.02', + 'summary': 'Add Product sku weight in Sale Order, product weight, sale weight, sale order weight, total weight, kg kg(s) lb lb(s) support', 'sequence': 10, 'license': 'LGPL-3', 'description': """ - Add product sku weight in Sale Order. Unit of measure auto weight. - Calculates total weight of a sale order, which is the sum of individual weights of each unit of the products in the order + Add product sku weight in Sale Order. Unit of measure auto weight, kg kg(s) lb lb(s) support. + Calculates total weight of a sale order, which is the sum of individual weights of each unit of the products in the order。 + Support kg(s) or lb(s) """, 'category': 'Sales', 'author': 'Sunpop.cn', diff --git a/app_product_weight_sale/models/sale_order.py b/app_product_weight_sale/models/sale_order.py index 83a43d74..bf347fd7 100644 --- a/app_product_weight_sale/models/sale_order.py +++ b/app_product_weight_sale/models/sale_order.py @@ -7,13 +7,23 @@ from odoo import api, fields, models, _ class SaleOrder(models.Model): _inherit = "sale.order" - weight_total = fields.Float(string='Total Weight(kg)', compute='_compute_weight_total') + def _get_default_weight_uom_name(self): + get_param = self.env['ir.config_parameter'].sudo().get_param + product_weight_in_lbs_param = get_param('product.weight_in_lbs') + if product_weight_in_lbs_param == '1': + return self.env.ref('uom.product_uom_lb').name + else: + return self.env.ref('uom.product_uom_kgm').name + + weight_total = fields.Float(string='Total Weight', compute='_compute_weight_total') + # 重量显示的单位 + weight_uom_name = fields.Char(string='Weight Measure', default=_get_default_weight_uom_name, readonly=True) def _compute_weight_total(self): - for sale in self: + for rec in self: weight_tot = 0 - for line in sale.order_line: + for line in rec.order_line: if line.product_id: weight_tot += line.weight_subtotal or 0.0 - sale.weight_total = weight_tot + rec.weight_total = weight_tot diff --git a/app_product_weight_sale/models/sale_order_line.py b/app_product_weight_sale/models/sale_order_line.py index 9d1a77b6..b91f3e56 100644 --- a/app_product_weight_sale/models/sale_order_line.py +++ b/app_product_weight_sale/models/sale_order_line.py @@ -11,17 +11,19 @@ class SaleOrderLine(models.Model): # 显示的单位,影响性能暂时不使用 # weight_uom_name = fields.Char(string='Weight Measure', related='product_id.weight_uom_id.name', readonly=True) - weight = fields.Float(string='Weight', related='product_id.weight', store=True, readonly=True) - weight_subtotal = fields.Float(string='Weight Subtotal', compute='_compute_weight_subtotal', - inverse='_set_weight_subtotal', store=True) + weight = fields.Float(string='Weight', compute='_compute_weight', readonly=True) + weight_subtotal = fields.Float(string='Weight Subtotal', compute='_compute_weight', store=True) @api.multi - @api.depends('product_id', 'weight', 'product_uom', 'product_uom_qty') - def _compute_weight_subtotal(self): + @api.depends('product_id', 'product_uom', 'product_qty') + def _compute_weight(self): for line in self: + weight = 0 weight_subtotal = 0 if line.product_id and line.product_id.weight: - weight_subtotal += (line.product_id.weight * line.product_uom_qty / line.product_uom.factor) + weight = line.product_id.weight / line.product_uom.factor + weight_subtotal += (weight * line.product_qty) + line.weight = weight line.weight_subtotal = weight_subtotal @api.one diff --git a/app_product_weight_sale/static/description/banner.jpg b/app_product_weight_sale/static/description/banner.jpg index c064ed42..e3de4f89 100644 Binary files a/app_product_weight_sale/static/description/banner.jpg and b/app_product_weight_sale/static/description/banner.jpg differ diff --git a/app_product_weight_sale/static/description/banner.png b/app_product_weight_sale/static/description/banner.png new file mode 100644 index 00000000..205ef176 Binary files /dev/null and b/app_product_weight_sale/static/description/banner.png differ diff --git a/app_product_weight_sale/static/description/demo1.jpg b/app_product_weight_sale/static/description/demo1.jpg new file mode 100644 index 00000000..c064ed42 Binary files /dev/null and b/app_product_weight_sale/static/description/demo1.jpg differ diff --git a/app_product_weight_sale/static/description/index.html b/app_product_weight_sale/static/description/index.html index 2bc482b2..00adfd61 100644 --- a/app_product_weight_sale/static/description/index.html +++ b/app_product_weight_sale/static/description/index.html @@ -3,32 +3,46 @@
-This module from Sunpop.cn manages to calculate total weight of a sale order, which is the sum of individual weights of each unit of the products in the order. -
--The product form has a field 'Weight', which stores the weight of the product in Kg. -
+
+
- The module adds a field 'Net Weight' in sale order line, which calculates the Order line weight based on Order line Quantity and Unit of Measure. The new field 'Total Weight' in Sale Order would be the sum of sale order line weights. -
-
+
-The calculation uses the following formula: -
++ The calculation uses the following formula: +
-Sale_order_line_net_weight = (line_product_weight * line_product_uom_qty / line_product_uom_factor)
+order_line_net_weight = (line_product_weight / line_product_uom_factor)
-weight_total = sum(Sale_order_line_net_weight)
+weight_total = sum(order_line_net_weight)