Skip to content

Commit

Permalink
Merge pull request #119 from akretion/10-roulier-accurate-price
Browse files Browse the repository at this point in the history
[10.0] Better unit price computation
  • Loading branch information
hparfr authored May 30, 2018
2 parents 4eebd58 + e18851e commit 882d83b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions delivery_roulier/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import stock_picking
from . import stock_quant_package
from . import stock_pack_operation
38 changes: 38 additions & 0 deletions delivery_roulier/models/stock_pack_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.tools import float_is_zero


class StockPackOperation(models.Model):
_inherit = 'stock.pack.operation'

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')
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
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

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
2 changes: 1 addition & 1 deletion delivery_roulier/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.get_unit_price_for_customs()

category = picking.customs_category
return {
Expand Down
6 changes: 3 additions & 3 deletions delivery_roulier_option/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 882d83b

Please sign in to comment.