forked from OCA/delivery-carrier
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from akretion/10-roulier-accurate-price
[10.0] Better unit price computation
- Loading branch information
Showing
4 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters