Skip to content

Commit

Permalink
Merge 741f135 into d223bd3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mackilem committed Apr 16, 2019
2 parents d223bd3 + 741f135 commit 700ae35
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions br_purchase/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

from . import purchase
from . import account_invoice
from . import stock
15 changes: 11 additions & 4 deletions br_purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,28 @@ def _compute_tax_id(self):
@api.multi
def _get_stock_move_price_unit(self):
price = self.price_unit
order = self.order_id
ctx = self._prepare_tax_context()
tax_ids = self.taxes_id.with_context(**ctx)
taxes = tax_ids.compute_all(
price, self.order_id.currency_id,
self.product_qty, product=self.product_id,
price,
currency=self.order_id.currency_id,
quantity=1.0,
product=self.product_id,
partner=self.order_id.partner_id)

price = taxes['total_included']

for tax in taxes['taxes']:
# Quando o imposto não tem conta contábil, deduzimos que ele não é
# recuperável e portanto somamos ao custo, como partimos do valor
# já com imposto se existir conta diminuimos o valor deste imposto
if tax['account_id']:
price -= tax['amount']

price = price / self.product_qty
if self.product_uom.id != self.product_id.uom_id.id:
price *= self.product_uom.factor / self.product_id.uom_id.factor
if order.currency_id != order.company_id.currency_id:
price = order.currency_id.compute(price,
order.company_id.currency_id,
round=False)
return price
40 changes: 40 additions & 0 deletions br_purchase/models/stock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# © 2018 Mackilem Van der Laan, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class StockMove(models.Model):
_inherit = 'stock.move'

@api.multi
def _get_price_unit(self):
self.ensure_one()
if self.purchase_line_id \
and self.product_id.id == self.purchase_line_id.product_id.id:
line = self.purchase_line_id
order = line.order_id
ctx = line._prepare_tax_context()
tax_ids = line.taxes_id.with_context(**ctx)
price = line.price_unit
if line.taxes_id:
taxes = tax_ids.compute_all(
price,
currency=line.order_id.currency_id,
quantity=1.0,
product=self.product_id,
partner=line.order_id.partner_id)

price = taxes['total_included']
for tax in taxes['taxes']:
if tax['account_id']:
price -= tax['amount']
if self.product_uom.id != self.product_id.uom_id.id:
price *= self.product_uom.factor/self.product_id.uom_id.factor
if order.currency_id != order.company_id.currency_id:
price = order.currency_id.compute(price,
order.company_id.currency_id,
round=False)
return price
return super(StockMove, self)._get_price_unit()

0 comments on commit 700ae35

Please sign in to comment.