From 42cb8c56b706ea2614428aaad8aa788ec4852b3c Mon Sep 17 00:00:00 2001 From: ivan deng Date: Fri, 14 Dec 2018 12:20:13 +0800 Subject: [PATCH] update sale weight --- app_product_weight_sale/__manifest__.py | 8 +++++--- app_product_weight_sale/i18n/zh_CN.po | 2 +- app_product_weight_sale/models/sale_order.py | 6 +++--- app_product_weight_sale/models/sale_order_line.py | 9 +++++---- app_product_weight_sale/static/description/index.html | 2 +- app_product_weight_sale/views/sale_order_views.xml | 8 ++++---- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app_product_weight_sale/__manifest__.py b/app_product_weight_sale/__manifest__.py index 67de7573..e64bada1 100644 --- a/app_product_weight_sale/__manifest__.py +++ b/app_product_weight_sale/__manifest__.py @@ -2,19 +2,21 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. { - 'name': 'App Sales Order Weight', + 'name': 'App Product Weight in Sales Order', 'version': '12.0.11.26', - 'summary': 'Add sku weight in Sale Order', + 'summary': 'Add Product sku weight in Sale Order, product weight, sale weight, total weight', 'sequence': 10, 'license': 'LGPL-3', 'description': """ - Add sku weight in Sale Order. + Add product sku weight in Sale Order. Calculates total weight of a sale order, which is the sum of individual weights of each unit of the products in the order """, 'category': 'Sales', 'author': 'Sunpop.cn', 'website': 'http://www.sunpop.cn', 'images': ['static/description/banner.jpg'], + 'currency': 'EUR', + 'price': 38, 'depends': ['sale_management'], 'data': [ 'views/sale_order_views.xml', diff --git a/app_product_weight_sale/i18n/zh_CN.po b/app_product_weight_sale/i18n/zh_CN.po index b0a0dd49..1e294ea5 100644 --- a/app_product_weight_sale/i18n/zh_CN.po +++ b/app_product_weight_sale/i18n/zh_CN.po @@ -21,7 +21,7 @@ msgid " kg" msgstr " 公斤" #. module: app_product_weight_sale -#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_total_weight +#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_weight_total msgid "Total Weight(kg)" msgstr "总重量(kg)" diff --git a/app_product_weight_sale/models/sale_order.py b/app_product_weight_sale/models/sale_order.py index 9f4818bf..83a43d74 100644 --- a/app_product_weight_sale/models/sale_order.py +++ b/app_product_weight_sale/models/sale_order.py @@ -7,13 +7,13 @@ from odoo import api, fields, models, _ class SaleOrder(models.Model): _inherit = "sale.order" - total_weight = fields.Float(string='Total Weight(kg)', compute='_compute_weight_total') + weight_total = fields.Float(string='Total Weight(kg)', compute='_compute_weight_total') def _compute_weight_total(self): for sale in self: weight_tot = 0 for line in sale.order_line: if line.product_id: - weight_tot += line.weight or 0.0 - sale.total_weight = weight_tot + weight_tot += line.weight_subtotal or 0.0 + sale.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 31e3ba86..79851178 100644 --- a/app_product_weight_sale/models/sale_order_line.py +++ b/app_product_weight_sale/models/sale_order_line.py @@ -9,12 +9,13 @@ from odoo import api, fields, models, _ class SaleOrderLine(models.Model): _inherit = 'sale.order.line' - weight = fields.Float(string='Weight(kg)', compute='_compute_weight', - inverse='_set_weight', store=True) + weight = fields.Float(string='Weight', store=True) + weight_subtotal = fields.Float(string='Weight Subtotal', compute='_compute_weight_subtotal', + inverse='_set_weight_subtotal', store=True) @api.multi @api.depends('product_id', 'product_uom_qty') - def _compute_weight(self): + def _compute_weight_subtotal(self): for line in self: weight = 0 if line.product_id and line.product_id.weight: @@ -22,5 +23,5 @@ class SaleOrderLine(models.Model): line.weight = weight @api.one - def _set_weight(self): + def _set_weight_subtotal(self): pass diff --git a/app_product_weight_sale/static/description/index.html b/app_product_weight_sale/static/description/index.html index 8a244b65..eff49826 100644 --- a/app_product_weight_sale/static/description/index.html +++ b/app_product_weight_sale/static/description/index.html @@ -28,7 +28,7 @@ The calculation uses the following formula:

Sale_order_line_net_weight = (line_product_weight * line_product_uom_qty / line_product_uom_factor)
-Total_weight = sum(Sale_order_line_net_weight) +weight_total = sum(Sale_order_line_net_weight)

diff --git a/app_product_weight_sale/views/sale_order_views.xml b/app_product_weight_sale/views/sale_order_views.xml index 90bfb434..091de436 100644 --- a/app_product_weight_sale/views/sale_order_views.xml +++ b/app_product_weight_sale/views/sale_order_views.xml @@ -9,7 +9,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -34,8 +34,8 @@
-