Skip to content

Commit

Permalink
Merge f372b95 into c999a2e
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Sep 11, 2018
2 parents c999a2e + f372b95 commit 36a655a
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 19 deletions.
2 changes: 1 addition & 1 deletion br_account/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def compute_all(self, price_unit, currency=None, quantity=1.0,
for tax in taxes:
tax_id = self.filtered(lambda x: x.id == tax['id'])
if not tax_id.price_include:
total_included += tax['amount']
total_included += round(tax['amount'], 2)

return {
'taxes': sorted(taxes, key=lambda k: k['sequence']),
Expand Down
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
1 change: 1 addition & 0 deletions br_purchase_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
'data': [
'views/purchase_stock_view.xml',
'views/account_invoice.xml',
],
'auto_install': True,
}
22 changes: 20 additions & 2 deletions br_purchase_stock/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo import models, api, fields
from odoo.addons import decimal_precision as dp


class AccountInvoice(models.Model):
Expand All @@ -14,4 +14,22 @@ def _prepare_invoice_line_from_po_line(self, line):
res['valor_seguro'] = line.valor_seguro
res['outras_despesas'] = line.outras_despesas
res['valor_frete'] = line.valor_frete
res['ii_valor_despesas'] = line.valor_aduana
return res

total_despesas_aduana = fields.Float(
string='Despesas Aduaneiras', digits=dp.get_precision('Account'),
compute="_compute_amount")

@api.one
@api.depends('invoice_line_ids.price_subtotal',
'invoice_line_ids.price_total',
'tax_line_ids.amount',
'currency_id', 'company_id')
def _compute_amount(self):
super(AccountInvoice, self)._compute_amount()
lines = self.invoice_line_ids
self.total_despesas_aduana = sum(l.ii_valor_despesas for l in lines)
self.amount_total = self.total_bruto - self.total_desconto + \
self.total_tax + self.total_frete + self.total_seguro + \
self.total_despesas
60 changes: 52 additions & 8 deletions br_purchase_stock/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,75 @@ def _amount_all(self):
order.total_frete + order.total_seguro +
order.total_despesas - order.total_desconto,
})
self._onchange_despesas_frete_seguro()

def _calc_ratio(self, qty, total):
if total > 0:
return qty / total
else:
return 0

@api.onchange('total_despesas', 'total_seguro', 'total_frete')
def _onchange_despesas_frete_seguro(self):
def calc_rateio(self, line, total):
porcentagem = self._calc_ratio(line.valor_bruto, total)
frete = self.total_frete * porcentagem
seguro = self.total_seguro * porcentagem
despesas = self.total_despesas * porcentagem
aduana = self.total_despesas_aduana * porcentagem
line.update({
'valor_seguro': seguro,
'valor_frete': frete,
'outras_despesas': despesas,
'valor_aduana': aduana
})
return frete, seguro, despesas, aduana

def calc_total_amount(self):
amount = 0
for line in self.order_line:
if line.product_id.fiscal_type == 'product':
amount += line.valor_bruto
return amount

@api.onchange('total_despesas', 'total_seguro',
'total_frete', 'total_despesas_aduana')
def _onchange_despesas_frete_seguro(self):
amount = self.calc_total_amount()
sub_frete = self.total_frete
sub_seguro = self.total_seguro
sub_aduana = self.total_despesas_aduana
sub_desp = self.total_despesas
for l in self.order_line:
if l.product_id.fiscal_type == 'service':
continue
percentual = self._calc_ratio(l.valor_bruto, amount)
l.update({
'valor_seguro': self.total_seguro * percentual,
'valor_frete': self.total_frete * percentual,
'outras_despesas': self.total_despesas * percentual
})
else:
frete, seguro, despesas, aduana = self.calc_rateio(
l, amount)
sub_frete -= round(frete, 2)
sub_seguro -= round(seguro, 2)
sub_aduana -= round(aduana, 2)
sub_desp -= round(despesas, 2)
if self.order_line:
self.order_line[0].update({
'valor_seguro':
self.order_line[0].valor_seguro + sub_seguro,
'valor_frete':
self.order_line[0].valor_frete + sub_frete,
'outras_despesas':
self.order_line[0].outras_despesas + sub_desp,
'valor_aduana':
self.order_line[0].valor_aduana + sub_aduana
})

total_despesas = fields.Float(
string='Despesas ( + )', default=0.00,
digits=dp.get_precision('Account'),
readonly=True, states={'draft': [('readonly', False)],
'sent': [('readonly', False)]})
total_despesas_aduana = fields.Float(
string='Despesas Aduaneiras', default=0.00,
digits=dp.get_precision('Account'),
readonly=True, states={'draft': [('readonly', False)],
'sent': [('readonly', False)]})
total_seguro = fields.Float(
string='Seguro ( + )', default=0.00,
digits=dp.get_precision('Account'),
Expand All @@ -68,6 +108,8 @@ def _prepare_tax_context(self):
'valor_frete': self.valor_frete,
'valor_seguro': self.valor_seguro,
'outras_despesas': self.outras_despesas,
'ii_despesas': self.valor_aduana,
'fiscal_type': self.fiscal_position_type,
})
return res

Expand All @@ -77,3 +119,5 @@ def _prepare_tax_context(self):
'Despesas', default=0.0, digits=dp.get_precision('Account'))
valor_frete = fields.Float(
'Frete', default=0.0, digits=dp.get_precision('Account'))
valor_aduana = fields.Float(
default=0.0, digits=dp.get_precision('Account'))
45 changes: 45 additions & 0 deletions br_purchase_stock/views/account_invoice.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="br_account_product_invoice_form" model="ir.ui.view">
<field name="name">br_account_product.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="br_account.view_br_account_invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree" position="inside">
<field name="ii_valor_despesas" invisible="1" />
</xpath>
<field name="total_frete" position="after">
<field name="fiscal_position_type" invisible="1"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
</field>
</record>

<!-- Vendor view -->
<record id="br_account_product_invoice_supplier_form" model="ir.ui.view">
<field name="name">br_account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="br_account.view_br_account_invoice_supplier_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree" position="inside">
<field name="ii_valor_despesas" invisible="1" />
</xpath>
<field name="total_frete" position="after">
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
</field>
</record>

<record model="ir.ui.view" id="view_br_account_invoice_line_form">
<field name="name">br_account.invoice.line.form</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="br_account.view_br_account_invoice_line_form" />
<field name="priority">36</field>
<field name="arch" type="xml">
<field name="price_subtotal" position="after">
<field name="ii_valor_despesas" invisible="1" />
</field>
</field>
</record>

</odoo>
5 changes: 4 additions & 1 deletion br_purchase_stock/views/purchase_stock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='product_qty']" position="after">
<field name="outras_despesas" invisible="1" />
<field name="outras_despesas" invisible="1" />
<field name="valor_seguro" invisible="1" />
<field name="valor_frete" invisible="1" />
<field name="valor_aduana" invisible="1" />
<field name="price_total" invisible="1" />
</xpath>
<field name="amount_tax" position="after">
<field name="total_despesas" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="total_despesas_aduana" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="total_seguro" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="total_frete" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
Expand Down
13 changes: 11 additions & 2 deletions br_stock_account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
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.multi
def copy(self, default=None):
new_acc_inv = super(AccountInvoice, self).copy(default)
if self.fiscal_position_type == 'import':
for i in range(len(new_acc_inv.invoice_line_ids)):
new_acc_inv.invoice_line_ids[i].import_declaration_ids = \
self.invoice_line_ids[i].import_declaration_ids
return new_acc_inv

@api.one
@api.depends('invoice_line_ids.price_subtotal',
Expand Down Expand Up @@ -131,7 +141,6 @@ 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
Expand Down
7 changes: 4 additions & 3 deletions br_stock_account/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def calc_ipi_base(self, price_base):
if "valor_seguro" in self.env.context:
base_ipi += self.env.context["valor_seguro"]
ii = self._compute_ii(price_base)
base_ipi += ii[0]['amount']

if (ii):
base_ipi += ii[0]['amount']
if "ipi_reducao_bc" in self.env.context:
reducao_ipi = self.env.context['ipi_reducao_bc']
return base_ipi * (1 - (reducao_ipi / 100.0))
Expand All @@ -40,7 +40,8 @@ def calc_icms_base(self, price_base, ipi_value):
base_icms += self.env.context["valor_seguro"]
if "icms_aliquota_reducao_base" in self.env.context:
reducao_icms = self.env.context['icms_aliquota_reducao_base']
base_icms += ii[0]['amount']
if ii:
base_icms += ii[0]['amount']
base_icms += ipi_value
base_icms += sum([tax['amount'] for tax in pis_cofins])
base_icms += self.env.context["ii_despesas"]
Expand Down

0 comments on commit 36a655a

Please sign in to comment.