Skip to content

Commit

Permalink
Rename method
Browse files Browse the repository at this point in the history
Move code that get SO from move to dedicated method
  • Loading branch information
alexis-via committed May 30, 2018
1 parent a4d7690 commit e18851e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions delivery_roulier/models/stock_pack_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@
# @author: Alexis de Lattre <[email protected]>
# 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
Expand All @@ -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
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'] = operation._roulier_get_unit_price_for_customs()
article['value'] = operation.get_unit_price_for_customs()

category = picking.customs_category
return {
Expand Down

0 comments on commit e18851e

Please sign in to comment.