From bf535ba2d8908575ec78c8ed6cbf33aa898c1cad Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 20 Apr 2018 17:23:50 +0200 Subject: [PATCH 1/3] delivery_roulier: accurate computation of unit price for CN23 --- delivery_roulier/models/__init__.py | 1 + .../models/stock_pack_operation.py | 39 +++++++++++++++++++ .../models/stock_quant_package.py | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 delivery_roulier/models/stock_pack_operation.py diff --git a/delivery_roulier/models/__init__.py b/delivery_roulier/models/__init__.py index f005d93463..ba875968ab 100644 --- a/delivery_roulier/models/__init__.py +++ b/delivery_roulier/models/__init__.py @@ -1,2 +1,3 @@ from . import stock_picking from . import stock_quant_package +from . import stock_pack_operation diff --git a/delivery_roulier/models/stock_pack_operation.py b/delivery_roulier/models/stock_pack_operation.py new file mode 100644 index 0000000000..513055d7fd --- /dev/null +++ b/delivery_roulier/models/stock_pack_operation.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api +from odoo.tools import float_is_zero + + +class StockPackOperation(models.Model): + _inherit = 'stock.pack.operation' + + @api.multi + def _roulier_get_unit_price_for_customs(self): + """This method is designed to be inherited for specific scenarios""" + self.ensure_one() + prec = self.env['decimal.precision'].precision_get( + 'Product Unit of Measure') + if ( + self.linked_move_operation_ids and + self.linked_move_operation_ids[0].move_id and + self.linked_move_operation_ids[0].move_id.procurement_id and + self.linked_move_operation_ids[0].move_id.procurement_id. + sale_line_id and + not float_is_zero( + self.linked_move_operation_ids[0].move_id.procurement_id. + sale_line_id.product_uom_qty, precision_digits=prec)): + sol = self.linked_move_operation_ids[0].move_id.\ + procurement_id.sale_line_id + price_unit_so_uom = sol.price_subtotal / sol.product_uom_qty + price_unit = sol.product_uom._compute_price( + price_unit_so_uom, self.product_uom_id) + else: + product = self.product_id + ato = self.env['account.tax'] + price_unit = ato._fix_tax_included_price_company( + product.list_price, product.taxes_id, ato, + self.picking_id.company_id) + return price_unit diff --git a/delivery_roulier/models/stock_quant_package.py b/delivery_roulier/models/stock_quant_package.py index 492d7f1e83..a7a2596f3b 100644 --- a/delivery_roulier/models/stock_quant_package.py +++ b/delivery_roulier/models/stock_quant_package.py @@ -279,7 +279,7 @@ def _roulier_get_customs(self, picking): article['originCountry'] = product.origin_country_id.code article['description'] = hs.description article['hs'] = hs.hs_code - article['value'] = product.list_price # unit price is expected + article['value'] = operation._roulier_get_unit_price_for_customs() category = picking.customs_category return { From a4d7690a729cae6672e1d71f360908737f33a51c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 20 Apr 2018 17:24:34 +0200 Subject: [PATCH 2/3] Improve error msg --- delivery_roulier_option/models/stock_picking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/delivery_roulier_option/models/stock_picking.py b/delivery_roulier_option/models/stock_picking.py index 45a8e71852..03f1e3b16d 100644 --- a/delivery_roulier_option/models/stock_picking.py +++ b/delivery_roulier_option/models/stock_picking.py @@ -15,7 +15,7 @@ class StockPicking(models.Model): display_insurance = fields.Boolean( compute='_compute_check_options', string="Define a condition to display/hide your custom Insurance" - "field with a decated view") + "field with a dedicated view") @implemented_by_carrier def _map_options(self): @@ -35,8 +35,8 @@ def _compute_check_options(self): rec.display_insurance = True else: rec.display_insurance = False - _logger.info(" >>> in _compute_check_options() %s" % - rec.display_insurance) + _logger.info("Picking %s display_insurance=%s", + rec.name, rec.display_insurance) @api.model def _roulier_map_options(self): From e18851eaed090c5847a70aaff59bf99a63dabf23 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 30 May 2018 20:31:49 +0200 Subject: [PATCH 3/3] Rename method Move code that get SO from move to dedicated method --- .../models/stock_pack_operation.py | 31 +++++++++---------- .../models/stock_quant_package.py | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/delivery_roulier/models/stock_pack_operation.py b/delivery_roulier/models/stock_pack_operation.py index 513055d7fd..143c96b83c 100644 --- a/delivery_roulier/models/stock_pack_operation.py +++ b/delivery_roulier/models/stock_pack_operation.py @@ -3,32 +3,23 @@ # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, api +from odoo import models from odoo.tools import float_is_zero class StockPackOperation(models.Model): _inherit = 'stock.pack.operation' - @api.multi - def _roulier_get_unit_price_for_customs(self): + def get_unit_price_for_customs(self): """This method is designed to be inherited for specific scenarios""" self.ensure_one() prec = self.env['decimal.precision'].precision_get( 'Product Unit of Measure') - if ( - self.linked_move_operation_ids and - self.linked_move_operation_ids[0].move_id and - self.linked_move_operation_ids[0].move_id.procurement_id and - self.linked_move_operation_ids[0].move_id.procurement_id. - sale_line_id and - not float_is_zero( - self.linked_move_operation_ids[0].move_id.procurement_id. - sale_line_id.product_uom_qty, precision_digits=prec)): - sol = self.linked_move_operation_ids[0].move_id.\ - procurement_id.sale_line_id - price_unit_so_uom = sol.price_subtotal / sol.product_uom_qty - price_unit = sol.product_uom._compute_price( + soline = self.get_sale_order_line() + if soline and not float_is_zero( + soline.product_uom_qty, precision_digits=prec): + price_unit_so_uom = soline.price_subtotal / soline.product_uom_qty + price_unit = soline.product_uom._compute_price( price_unit_so_uom, self.product_uom_id) else: product = self.product_id @@ -37,3 +28,11 @@ def _roulier_get_unit_price_for_customs(self): product.list_price, product.taxes_id, ato, self.picking_id.company_id) return price_unit + + def get_sale_order_line(self): + soline = self.linked_move_operation_ids and\ + self.linked_move_operation_ids[0].move_id and\ + self.linked_move_operation_ids[0].move_id.procurement_id and\ + self.linked_move_operation_ids[0].move_id.procurement_id.\ + sale_line_id or False + return soline diff --git a/delivery_roulier/models/stock_quant_package.py b/delivery_roulier/models/stock_quant_package.py index a7a2596f3b..dae29a9646 100644 --- a/delivery_roulier/models/stock_quant_package.py +++ b/delivery_roulier/models/stock_quant_package.py @@ -279,7 +279,7 @@ def _roulier_get_customs(self, picking): article['originCountry'] = product.origin_country_id.code article['description'] = hs.description article['hs'] = hs.hs_code - article['value'] = operation._roulier_get_unit_price_for_customs() + article['value'] = operation.get_unit_price_for_customs() category = picking.customs_category return {