Skip to content

Commit

Permalink
[IMP] Fix calculation of import taxes in purchase order and invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Sep 4, 2018
1 parent 9b07cf6 commit 265b7b8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
19 changes: 18 additions & 1 deletion br_purchase/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo import fields, models


class AccountInvoice(models.Model):
Expand Down Expand Up @@ -47,6 +47,7 @@ def _prepare_invoice_line_from_po_line(self, line):
res['tax_irrf_id'] = inss and inss.id or False
res['tax_inss_id'] = irrf and irrf.id or False

res['fiscal_position_type'] = line.fiscal_position_type
res['product_type'] = line.product_id.fiscal_type
res['company_fiscal_type'] = line.company_id.fiscal_type
res['cfop_id'] = line.cfop_id.id
Expand Down Expand Up @@ -108,3 +109,19 @@ def _prepare_invoice_line_from_po_line(self, line):
res['inss_aliquota'] = inss.amount or 0.0
res['irrf_aliquota'] = irrf.amount or 0.0
return res


class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'

fiscal_position_type = fields.Selection(
[('saida', 'Saída'), ('entrada', 'Entrada'),
('import', 'Entrada Importação')],
string="Tipo da posição fiscal")

def _prepare_tax_context(self):
res = super(AccountInvoiceLine, self)._prepare_tax_context()
res.update({
'fiscal_type': self.fiscal_position_type,
})
return res
8 changes: 7 additions & 1 deletion br_purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _prepare_tax_context(self):
self.icms_st_aliquota_reducao_base,
'ipi_reducao_bc': self.ipi_reducao_bc,
'icms_st_aliquota_deducao': self.icms_st_aliquota_deducao,
'fiscal_type': self.fiscal_position_type,
}

@api.depends('taxes_id', 'product_qty', 'price_unit', 'discount',
Expand Down Expand Up @@ -96,6 +97,10 @@ def _compute_amount(self):
'valor_desconto': desconto,
})

fiscal_position_type = fields.Selection(
[('saida', 'Saída'), ('entrada', 'Entrada'),
('import', 'Entrada Importação')],
string="Tipo da posição fiscal")
cfop_id = fields.Many2one('br_account.cfop', string="CFOP")

icms_cst_normal = fields.Char(string="CST ICMS", size=5)
Expand Down Expand Up @@ -186,7 +191,8 @@ def _compute_tax_id(self):
vals.get('tax_inss_id', empty)

line.update({
'taxes_id': [(6, None, [x.id for x in tax_ids if x])]
'taxes_id': [(6, None, [x.id for x in tax_ids if x])],
'fiscal_position_type': fpos.fiscal_type,
})

# Calcula o custo da mercadoria comprada
Expand Down
1 change: 1 addition & 0 deletions br_purchase/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<field name="inherit_id" ref="account.invoice_supplier_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree" position="inside">
<field name="fiscal_position_type" invisible="1"/>
<field name="icms_cst_normal" invisible="1" />
<field name="icms_csosn_simples" invisible="1" />
<field name="tax_icms_id" invisible="1"/>
Expand Down
2 changes: 2 additions & 0 deletions br_purchase/views/purchase_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<attribute name="domain">['|', ('fiscal_type', '=', 'import'), '|', ('fiscal_type', '=', 'entrada'), ('fiscal_type', '=', None)]</attribute>
</field>
<xpath expr="//field[@name='order_line']/tree/field[@name='taxes_id']" position="before">
<field name="fiscal_position_type" invisible="1" />
<field name="valor_bruto" widget="monetary" />
<field name="cfop_id" invisible="1" />
<field name="incluir_ipi_base" invisible="1" />
Expand All @@ -27,6 +28,7 @@
<field name="l10n_br_issqn_deduction" invisible="1" />
</xpath>
<xpath expr="//field[@name='order_line']/form/sheet/group/group/field[@name='price_unit']" position="after">
<field name="fiscal_position_type" invisible="1" />
<field name="valor_bruto" />
<field name="price_subtotal" />
<field name="cfop_id" invisible="1" />
Expand Down
7 changes: 3 additions & 4 deletions br_purchase_stock/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<field name="ii_valor_despesas" invisible="1" />
</xpath>
<field name="total_despesas" position="after">
<field name="pos_fiscal" invisible="1"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'invisible': [('pos_fiscal', '!=', 'import')]}"/>
<field name="fiscal_position_type" invisible="1"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
</field>
</record>
Expand All @@ -25,8 +25,7 @@
<field name="ii_valor_despesas" invisible="1" />
</xpath>
<field name="total_despesas" position="after">
<field name="pos_fiscal" invisible="1"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'invisible': [('pos_fiscal', '!=', 'import')]}"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
</field>
</record>
Expand Down
9 changes: 4 additions & 5 deletions br_stock_account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
class AccountInvoice(models.Model):
_inherit = 'account.invoice'

pos_fiscal = fields.Selection(related='fiscal_position_id.fiscal_type')
fiscal_position_type = fields.Selection(
related='fiscal_position_id.fiscal_type', readonly=True)

@api.one
@api.depends('invoice_line_ids.price_subtotal',
'invoice_line_ids.price_total',
'tax_line_ids.amount',
'currency_id', 'company_id', 'fiscal_position_id')
'currency_id', 'company_id')
def _compute_amount(self):
super(AccountInvoice, self)._compute_amount()
lines = self.invoice_line_ids
Expand Down Expand Up @@ -131,14 +132,12 @@ def _prepare_tax_context(self):
'valor_frete': self.valor_frete,
'valor_seguro': self.valor_seguro,
'outras_despesas': self.outras_despesas,
'fiscal_type': self.invoice_id.fiscal_position_id.fiscal_type,
'ii_despesas': self.ii_valor_despesas,
})
return res

@api.one
@api.depends('valor_frete', 'valor_seguro', 'outras_despesas',
'invoice_id.fiscal_position_id')
@api.depends('valor_frete', 'valor_seguro', 'outras_despesas')
def _compute_price(self):
super(AccountInvoiceLine, self)._compute_price()
total = self.valor_bruto - self.valor_desconto + self.valor_frete + \
Expand Down

0 comments on commit 265b7b8

Please sign in to comment.