update sale weight

This commit is contained in:
ivan deng
2018-12-14 12:20:13 +08:00
parent fabe8a775b
commit 42cb8c56b7
6 changed files with 19 additions and 16 deletions

View File

@@ -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',

View File

@@ -21,7 +21,7 @@ msgid "<span> kg</span>"
msgstr "<span> 公斤</span>"
#. 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)"

View File

@@ -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

View File

@@ -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

View File

@@ -28,7 +28,7 @@ The calculation uses the following formula:
<p class='oe_mt32'>
Sale_order_line_net_weight = (line_product_weight * line_product_uom_qty / line_product_uom_factor)
<br/>
Total_weight = sum(Sale_order_line_net_weight)
weight_total = sum(Sale_order_line_net_weight)
</p>
</div>

View File

@@ -9,7 +9,7 @@
<field name="inherit_id" ref="sale.view_order_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="after">
<field name="total_weight"/>
<field name="weight_total"/>
</xpath>
</field>
</record>
@@ -20,7 +20,7 @@
<field name="inherit_id" ref="sale.view_quotation_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="after">
<field name="total_weight"/>
<field name="weight_total"/>
</xpath>
</field>
</record>
@@ -34,8 +34,8 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='note']" position="before">
<div>
<label for="total_weight" name="total_weight" string="Total Weight: " class="oe_inline"/>
<field name="total_weight" class="oe_inline"/><span> kg</span>
<label for="weight_total" name="weight_total" string="Total Weight: " class="oe_inline"/>
<field name="weight_total" class="oe_inline"/><span> kg</span>
</div>
<newline/>
</xpath>