update all weight

This commit is contained in:
ivan deng
2019-01-28 18:41:07 +08:00
parent 13c52e4f1b
commit 598d5037fe
4 changed files with 34 additions and 36 deletions

View File

@@ -4,10 +4,10 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0+e-20181221\n" "Project-Id-Version: Odoo Server 12.0+e-20190124\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-01-02 15:10+0000\n" "POT-Creation-Date: 2019-01-28 10:38+0000\n"
"PO-Revision-Date: 2019-01-02 15:10+0000\n" "PO-Revision-Date: 2019-01-28 10:38+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@@ -26,7 +26,9 @@ msgid "Sales Order Line"
msgstr "销售订单行" msgstr "销售订单行"
#. module: app_product_weight_sale #. module: app_product_weight_sale
#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order__weight_total #: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order__weight
#: model_terms:ir.ui.view,arch_db:app_product_weight_sale.sale_quotation_weight_tree
#: model_terms:ir.ui.view,arch_db:app_product_weight_sale.sale_weight_tree
msgid "Total Weight" msgid "Total Weight"
msgstr "总重量" msgstr "总重量"
@@ -35,23 +37,18 @@ msgstr "总重量"
msgid "Total Weight:" msgid "Total Weight:"
msgstr "总重量" msgstr "总重量"
#. module: app_product_weight_sale
#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_line__weight
msgid "Weight"
msgstr "单位重量"
#. module: app_product_weight_sale #. module: app_product_weight_sale
#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order__weight_uom_name #: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order__weight_uom_name
msgid "Weight Measure" msgid "Weight Measure"
msgstr "重量单位" msgstr "重量单位"
#. module: app_product_weight_sale #. module: app_product_weight_sale
#: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_line__weight_subtotal #: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_line__weight
msgid "Weight Subtotal" msgid "Weight Subtotal"
msgstr "重量小计" msgstr "重量小计"
#. module: app_product_weight_sale #. module: app_product_weight_sale
#: model:ir.model.fields,help:app_product_weight_sale.field_sale_order_line__weight #: model:ir.model.fields,field_description:app_product_weight_sale.field_sale_order_line__weight_unit
msgid "Weight of the product, packaging not included. The unit of measure can be changed in the general settings" msgid "Weight Unit"
msgstr "产品重量、包装不包括在内。可以在一般设置中改变测量单位。" msgstr "单位重量"

View File

@@ -15,15 +15,17 @@ class SaleOrder(models.Model):
else: else:
return self.env.ref('uom.product_uom_kgm').name return self.env.ref('uom.product_uom_kgm').name
weight_total = fields.Float(string='Total Weight', compute='_compute_weight_total') weight = fields.Float(string='Total Weight', compute='_compute_weight')
# 重量显示的单位 # 重量显示的单位
weight_uom_name = fields.Char(string='Weight Measure', default=_get_default_weight_uom_name, readonly=True) weight_uom_name = fields.Char(string='Weight Measure', default=_get_default_weight_uom_name, readonly=True)
def _compute_weight_total(self): @api.multi
@api.depends('order_line.weight')
def _compute_weight(self):
for rec in self: for rec in self:
weight_tot = 0 weight_tot = 0
for line in rec.order_line: for line in rec.order_line:
if line.product_id: if line.product_id:
weight_tot += line.weight_subtotal or 0.0 weight_tot += line.weight or 0.0
rec.weight_total = weight_tot rec.weight = weight_tot

View File

@@ -11,23 +11,22 @@ class SaleOrderLine(models.Model):
# 显示的单位,影响性能暂时不使用 # 显示的单位,影响性能暂时不使用
# weight_uom_name = fields.Char(string='Weight Measure', related='product_id.weight_uom_id.name', readonly=True) # weight_uom_name = fields.Char(string='Weight Measure', related='product_id.weight_uom_id.name', readonly=True)
weight = fields.Float(string='Weight', compute='_compute_weight', store=True) # 调整,根据 delivery 模块,将 weight 作为 该行合计weight_unit 作为该单位的
weight_subtotal = fields.Float(string='Weight Subtotal', compute='_compute_weight', store=True) weight_unit = fields.Float(string='Weight Unit', compute='_compute_weight', store=True)
weight = fields.Float(string='Weight Subtotal', compute='_compute_weight', store=True)
@api.multi @api.multi
@api.depends('product_id', 'product_uom', 'product_uom_qty') @api.depends('product_id', 'product_uom', 'product_uom_qty')
def _compute_weight(self): def _compute_weight(self):
for line in self: for line in self.filtered(lambda rec: rec.product_id.weight > 0.00):
weight = 0 weight = 0
weight_subtotal = 0 try:
if line.product_id and line.product_id.weight: weight_unit = line.product_id.weight / line.product_uom.factor
try: except:
weight = line.product_id.weight / line.product_uom.factor weight_unit = line.product_id.weight
except: weight += (weight_unit * line.product_uom_qty)
weight = line.product_id.weight line.weight_unit = weight_unit
weight_subtotal += (weight * line.product_uom_qty)
line.weight = weight line.weight = weight
line.weight_subtotal = weight_subtotal
@api.one @api.one
def _set_weight_subtotal(self): def _set_weight_subtotal(self):

View File

@@ -9,7 +9,7 @@
<field name="inherit_id" ref="sale.view_order_tree"/> <field name="inherit_id" ref="sale.view_order_tree"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='amount_total']" position="before"> <xpath expr="//field[@name='amount_total']" position="before">
<field name="weight_total" sum="Total Weight"/> <field name="weight" sum="Total Weight"/>
</xpath> </xpath>
</field> </field>
</record> </record>
@@ -20,7 +20,7 @@
<field name="inherit_id" ref="sale.view_quotation_tree"/> <field name="inherit_id" ref="sale.view_quotation_tree"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='amount_total']" position="before"> <xpath expr="//field[@name='amount_total']" position="before">
<field name="weight_total" sum="Total Weight"/> <field name="weight" sum="Total Weight"/>
</xpath> </xpath>
</field> </field>
</record> </record>
@@ -34,18 +34,18 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='note']" position="before"> <xpath expr="//field[@name='note']" position="before">
<div> <div>
<label for="weight_total" name="weight_total" string="Total Weight: " class="oe_inline"/> <label for="weight" name="weight" string="Total Weight: " class="oe_inline"/>
<field name="weight_total" class="oe_inline"/><span> <field name="weight_uom_name" class="oe_inline"/></span> <field name="weight" class="oe_inline"/><span> <field name="weight_uom_name" class="oe_inline"/></span>
</div> </div>
<newline/> <newline/>
</xpath> </xpath>
<xpath expr="//field[@name='order_line']/tree//field[@name='product_uom']" position="after"> <xpath expr="//field[@name='order_line']/tree//field[@name='product_uom']" position="after">
<field name="weight_unit" invisible="1"/>
<field name="weight"/> <field name="weight"/>
<field name="weight_subtotal"/>
</xpath> </xpath>
<xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="before"> <xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="before">
<field name="weight"/> <field name="weight_unit" invisible="1"/>
<field name="weight_subtotal"/> <field name="weight"/>
</xpath> </xpath>
</field> </field>
</record> </record>