From 4809e8a0bd399392319b6e35099ecded6a47be7e Mon Sep 17 00:00:00 2001 From: gregoire Date: Mon, 21 Mar 2016 22:19:49 +0100 Subject: [PATCH] add display_weight with an if on the compute method --- beesdoo_product/models/beesdoo_product.py | 26 +++++++---------------- beesdoo_product/views/beesdoo_product.xml | 8 +++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py index b0fd8be..c613da4 100644 --- a/beesdoo_product/models/beesdoo_product.py +++ b/beesdoo_product/models/beesdoo_product.py @@ -10,33 +10,24 @@ class BeesdooProduct(models.Model): fair_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'fair')]) origin_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'delivery')]) - display_unit = fields.Char() - default_reference_unit = fields.Char() - display_weight = fields.Integer(compute='get_display_weight') + display_unit = fields.Many2one('product.uom', required=True) + default_reference_unit = fields.Many2one('product.uom', required=True) + + display_weight = fields.Float(compute='get_display_weight') total = fields.Float(compute='get_total') total_with_vat = fields.Float(compute='get_total_with_vat') + @api.one + @api.depends('weight', 'display_unit') def get_display_weight(self): - pass - - + if self.display_unit: + self.display_weight = self.weight / self.display_unit.factor def get_total(self): price_ht = self.env['product.pricelist'].search([])[0].price_get(self.id, 1)[1] self.total = price_ht - # grand_total_by_unit = fields.Float(compute='get_grand_total_by_unit') - # - # grand_total = fields.Float(compute='get_grand_total') - # - # def get_grand_total(self): - # self.grand_total = self.env['sale.order.line'] * self.price - # - # def get_grand_total_by_unit(self): - # self.grand_total_by_unit = self.grand_total * self.unit_price - # product.supplierinfo - def get_total_with_vat(self): tax_amount_sum = 0.0 for tax in self.taxes_id: @@ -44,7 +35,6 @@ class BeesdooProduct(models.Model): self.total_with_vat = self.total * (100.0 + tax_amount_sum) / 100 - class BeesdooProductLabel(models.Model): _name = 'beesdoo.product.label' diff --git a/beesdoo_product/views/beesdoo_product.xml b/beesdoo_product/views/beesdoo_product.xml index a740a2f..a99c512 100644 --- a/beesdoo_product/views/beesdoo_product.xml +++ b/beesdoo_product/views/beesdoo_product.xml @@ -52,17 +52,17 @@ - + + + + - - -