[IMP] delivery: add fields for retrieving the bulk weight and the weight of the packages of a picking

As the transporter interfaces will put a label on every package,
it is in handy to have a field with the list of the final packages
(and their weights) treated in  the picking.
We give a weight for the products that are not in a package also(bulk).
We only put the weight on the package in the views.

The weights in the product form views should appear entirely or not in
product / product templates (only when only 1 variant)
(attrs was only on the field, not label, ...)

The digits= for the weights are not needed as there is a decimal precision
on these fields.
This commit is contained in:
Josse Colpaert
2015-09-09 17:11:54 +02:00
parent cdc55cf8a6
commit a934b9e1ba
3 changed files with 61 additions and 12 deletions
+40
View File
@@ -6,6 +6,22 @@ from openerp.exceptions import UserError
import openerp.addons.decimal_precision as dp
class StockQuantPackage(models.Model):
_inherit = "stock.quant.package"
@api.one
@api.depends('quant_ids', 'children_ids')
def _compute_weight(self):
weight = 0
for quant in self.quant_ids:
weight += quant.qty * quant.product_id.weight
for pack in self.children_ids:
pack._compute_weight()
weight += pack.weight
self.weight = weight
weight = fields.Float(compute='_compute_weight')
class StockPicking(models.Model):
_inherit = 'stock.picking'
@@ -14,6 +30,28 @@ class StockPicking(models.Model):
uom_categ_id = self.env.ref('product.product_uom_categ_kgm').id
return self.env['product.uom'].search([('category_id', '=', uom_categ_id), ('factor', '=', 1)], limit=1)
@api.one
@api.depends('pack_operation_ids')
def _compute_packages(self):
self.ensure_one()
packs = set()
for packop in self.pack_operation_ids:
if packop.result_package_id:
packs.add(packop.result_package_id.id)
elif packop.package_id and not packop.product_id:
packs.add(packop.package_id.id)
self.package_ids = list(packs)
@api.one
@api.depends('pack_operation_ids')
def _compute_bulk_weight(self):
weight = 0.0
uom_obj = self.env['product.uom']
for packop in self.pack_operation_ids:
if packop.product_id and not packop.result_package_id:
weight += uom_obj._compute_qty_obj(packop.product_uom_id , packop.product_qty, packop.product_id.uom_id) * packop.product_id.weight
self.weight_bulk = weight
carrier_price = fields.Float(string="Shipping Cost", readonly=True)
delivery_type = fields.Selection(related='carrier_id.delivery_type', readonly=True)
carrier_id = fields.Many2one("delivery.carrier", string="Carrier")
@@ -22,6 +60,8 @@ class StockPicking(models.Model):
carrier_tracking_ref = fields.Char(string='Carrier Tracking Ref', copy=False)
number_of_packages = fields.Integer(string='Number of Packages', copy=False)
weight_uom_id = fields.Many2one('product.uom', string='Unit of Measure', required=True, readonly="1", help="Unit of measurement for Weight", default=_default_uom)
package_ids = fields.Many2many('stock.quant.package', compute='_compute_packages', string='Packages')
weight_bulk = fields.Float('Bulk Weight', compute='_compute_bulk_weight')
@api.depends('product_id', 'move_lines')
def _cal_weight(self):
+11
View File
@@ -195,6 +195,17 @@
</field>
</record>
<record id="view_quant_package_weight_form" model="ir.ui.view">
<field name="name">stock.quant.package.weight.form</field>
<field name="model">stock.quant.package</field>
<field name="inherit_id" ref="stock.view_quant_package_form"/>
<field name="arch" type="xml">
<field name="company_id" position="before">
<field name="weight"/>
</field>
</field>
</record>
<record id="view_move_withweight_form" model="ir.ui.view">
<field name="name">stock.move.form.weight</field>
<field name="model">stock.move</field>
+10 -12
View File
@@ -125,11 +125,9 @@
<field name="categ_id" string="Internal Category"/>
</group>
<group name="group_lots_and_weight">
<label for="weight"/>
<div class="o_row" name="weight">
<field digits="(14, 3)" name="weight" string="Weight"
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}"/>
<span>kg</span>
<label for="weight" attrs="{'invisible':[('type', 'not in', ['product', 'consu']), ('product_variant_count', '&gt;', 1)]}"/>
<div class="o_row" name="weight" attrs="{'invisible':[('type', 'not in', ['product', 'consu']), ('product_variant_count', '&gt;', 1)]}">
<field name="weight" string="Weight"/>
</div>
</group>
</group>
@@ -265,7 +263,7 @@
</div>
<label for="weight"/>
<div class="o_row">
<field digits="(14, 3)" name="weight"/>
<field name="weight"/>
<span>kg</span>
</div>
</group>
@@ -482,12 +480,12 @@
<field name="standard_price" attrs="{'invisible':[('product_variant_count','=', 1)]}"
widget='monetary' options="{'currency_field': 'currency_id'}"/>
</field>
<field name="weight" position="replace">
<field digits="(14, 3)" name="volume"
attrs="{'invisible':['|', ('type', 'not in', ['product', 'consu']),('product_variant_count','=',1)]}"/>
<field digits="(14, 3)" name="weight"
attrs="{'invisible':['|', ('type', 'not in', ['product', 'consu']),('product_variant_count','=',1)]}"/>
</field>
<label for="weight" position="attributes">
<attribute name="attrs">{'invisible':[('type', 'not in', ['product', 'consu'])]}</attribute>
</label>
<div name="weight" position="attributes">
<attribute name="attrs">{'invisible':[('type', 'not in', ['product', 'consu'])]}</attribute>
</div>
<xpath expr="//div[@class='oe_title']" position="inside">
<field name="attribute_value_ids" widget="many2many_tags" groups="product.group_product_variant"/>
</xpath>