Skip to content

Commit

Permalink
Merge branch '11.0' into 11.0-add-di
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaGD committed Apr 8, 2019
2 parents 522a6bb + d223bd3 commit 926b4f9
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 33 deletions.
4 changes: 3 additions & 1 deletion account_group_invoices/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ def _create_invoices_grouped(self, inv):
for org in inv_ids.filtered('origin').mapped('origin'):
origin += "%s, " % org
pgto_ids = inv_ids.mapped('payment_term_id')
mode_ids = inv_ids.mapped('payment_mode_id')
user_ids = inv_ids.mapped('user_id')
team_ids = inv_ids.mapped('team_id')
obs_ids = fpos_id.fiscal_observation_ids.ids
[i.action_invoice_cancel_paid() for i in inv_ids if i.state == "draft"]
gr_invoice_id = self.create({
'origin': origin or '',
'type': 'out_invoice',
Expand All @@ -107,6 +109,7 @@ def _create_invoices_grouped(self, inv):
'journal_id': journal_id.id,
'currency_id': company.currency_id.id,
'payment_term_id': pgto_ids[0].id if pgto_ids else False,
'payment_mode_id': mode_ids[0].id if mode_ids else False,
'fiscal_position_id': fpos_id.id,
'service_document_id': fpos_id.service_document_id.id,
'service_serie_id': fpos_id.service_serie_id.id,
Expand Down Expand Up @@ -142,7 +145,6 @@ def _create_invoices_grouped(self, inv):
</p>""" % (inv['rule'], gr_invoice_id.id, partner_id.name))

[i.message_post(cancel_msg) for i in inv_ids]
[i.action_invoice_cancel_paid() for i in inv_ids if i.state == "draft"]
msg_ids = ''
for id in inv_ids.ids:
msg_ids += """<a href='#' data-oe-model='account.invoice'
Expand Down
13 changes: 11 additions & 2 deletions br_account/models/account_invoice_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ def invoice_refund(self):
invoice_id = self.env['account.invoice'].search([
('id', '=', invoice_id)
])

invoice_id.write({'fiscal_position_id': self.fiscal_position_id.id})
fiscal_pos = self.fiscal_position_id
invoice_id.write({
'fiscal_position_id': fiscal_pos.id,
'product_serie_id': fiscal_pos.product_serie_id.id,
'product_document_id': fiscal_pos.product_document_id.id,
'service_serie_id': fiscal_pos.service_serie_id.id,
'service_document_id': fiscal_pos.service_document_id.id,
'fiscal_observation_ids': [(
6, False, [x.id for x in fiscal_pos.fiscal_observation_ids]
)]
})

if self.fiscal_position_id:
for item in invoice_id.invoice_line_ids:
Expand Down
3 changes: 3 additions & 0 deletions br_account_payment/views/account_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<field name="acc_number_dig" />
<field name="bank_agency_dig" />
</field>
<field name="currency_id" position="after">
<field name="l10n_br_sequence_statements" />
</field>
</field>
</record>

Expand Down
1 change: 1 addition & 0 deletions br_account_tax_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions br_account_tax_python/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# © 2019 Mackilem Van der Laan, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{ # pylint: disable=C8101,C8103
'name': "Define Taxes as Python Code - Pass extra variables",
'summary': "Allows to use python code to define taxes",
'description': """Allows to use python code to define taxes -
Define extra variables to calculate taxes in Brazil""",
'author': "Trustcode",
'website': "http://www.trustcode.com.br",
'category': 'account',
'version': '11.0.1.0.0',
'license': 'AGPL-3',
'contributors': [
'Mackilem Van der Laan <mack.vdl@gmail.com>',
],
'depends': [
'br_account',
'account_tax_python'
],
'data': [
'data/account_tax_data.xml'
],
}
68 changes: 68 additions & 0 deletions br_account_tax_python/data/account_tax_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="tax_pis_paulistana" model="account.tax">
<field name="description">PIS 1.05 Saída Paulistana</field>
<field name="name">PIS 1.05 Saída Paulistana</field>
<field name="domain">pis</field>
<field name="type_tax_use">sale</field>
<field name="amount_type">code</field>
<field name="amount">0</field>
<field eval="0" name="price_include"/>
<field name="python_compute">
result = 0.0
if invoice_amount and invoice_amount > 215.15:
result = round(base_amount * -0.0065, 3)
</field>
<field name="python_applicable">result = True</field>
</record>

<record id="tax_cofins_paulistana" model="account.tax">
<field name="description">COFINS 1.05 Saída Paulistana</field>
<field name="name">COFINS 1.05 Saída Paulistana</field>
<field name="domain">cofins</field>
<field name="type_tax_use">sale</field>
<field name="amount_type">code</field>
<field name="amount">0</field>
<field eval="0" name="price_include"/>
<field name="python_compute">
result = 0.0
if invoice_amount and invoice_amount > 215.15:
result = round(base_amount * -0.03, 3)
</field>
<field name="python_applicable">result = True</field>
</record>

<record id="tax_csll_paulistana" model="account.tax">
<field name="description">CSLL 1.05 Saída Paulistana</field>
<field name="name">CSLL 1.05 Saída Paulistana</field>
<field name="domain">csll</field>
<field name="type_tax_use">sale</field>
<field name="amount_type">code</field>
<field name="amount">0</field>
<field eval="0" name="price_include"/>
<field name="python_compute">
result = 0.0
if invoice_amount and invoice_amount > 215.15:
result = round(base_amount * -0.01, 3)
</field>
<field name="python_applicable">result = True</field>
</record>

<record id="tax_irrf_paulistana" model="account.tax">
<field name="description">IRRF 1.05 Saída Paulistana</field>
<field name="name">IRRF 1.05 Saída Paulistana</field>
<field name="domain">irrf</field>
<field name="type_tax_use">sale</field>
<field name="amount_type">code</field>
<field name="amount">0</field>
<field eval="0" name="price_include"/>
<field name="python_compute">
result = 0.0
if invoice_amount and invoice_amount > 666.66:
result = round(base_amount * -0.015, 3)
</field>
<field name="python_applicable">result = True</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions br_account_tax_python/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_invoice
from . import account_tax
15 changes: 15 additions & 0 deletions br_account_tax_python/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# © 2019 Mackilem Van der Laan, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


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

def _prepare_tax_context(self):
res = super(AccountInvoiceLine, self)._prepare_tax_context()
amount = (self.invoice_id.amount_total
+ self.quantity * self.price_unit)
res['invoice_amount'] = amount
return res
30 changes: 30 additions & 0 deletions br_account_tax_python/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# © 2019 Mackilem Van der Laan, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo.tools.safe_eval import safe_eval


class AccountTax(models.Model):
_inherit = 'account.tax'

def _compute_amount(self, base_amount, price_unit, quantity=1.0,
product=None, partner=None):
self.ensure_one()
if self.amount_type == 'code':
company = self.env.user.company_id
invoice_amount = self._context.get('invoice_amount', 0)
localdict = {
'invoice_amount': invoice_amount,
'base_amount': base_amount,
'price_unit': price_unit,
'quantity': quantity,
'product': product,
'partner': partner,
'company': company,
'context': self._context,
}
safe_eval(self.python_compute, localdict, mode="exec", nocopy=True)
return localdict['result']
return super(AccountTax, self)._compute_amount(
base_amount, price_unit, quantity, product, partner)
36 changes: 36 additions & 0 deletions br_nfe/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,28 @@ def _prepare_eletronic_invoice_values(self):
'xPed': self.pedido_compra or '',
'xCont': self.contrato_compra or '',
}

responsavel_tecnico = self.company_id.responsavel_tecnico_id
infRespTec = {}

if responsavel_tecnico:
if len(responsavel_tecnico.child_ids) == 0:
raise UserError(
"Adicione um contato para o responsável técnico!")

cnpj = re.sub(
'[^0-9]', '', responsavel_tecnico.cnpj_cpf)
fone = re.sub(
'[^0-9]', '', responsavel_tecnico.phone)
infRespTec = {
'CNPJ': cnpj or '',
'xContato': responsavel_tecnico.child_ids[0].name or '',
'email': responsavel_tecnico.email or '',
'fone': fone or '',
'idCSRT': self.company_id.id_token_csrt or '',
'hashCSRT': self._get_hash_csrt() or '',
}

vals = {
'Id': '',
'ide': ide,
Expand All @@ -756,6 +778,7 @@ def _prepare_eletronic_invoice_values(self):
'infAdic': infAdic,
'exporta': exporta,
'compra': compras,
'infRespTec': infRespTec,
}
if self.valor_servicos > 0.0:
vals.update({
Expand Down Expand Up @@ -1142,3 +1165,16 @@ def _create_response_cancel(self, code, motive, response, justificativa):
'view_mode': 'form',
'target': 'new',
}

def _get_hash_csrt(self):
chave_nfe = self.chave_nfe
csrt = self.company_id.csrt

if not csrt:
return

hash_csrt = "{0}{1}".format(csrt, chave_nfe)
hash_csrt = base64.b64encode(
hashlib.sha1(hash_csrt.encode()).digest())

return hash_csrt.decode("utf-8")
29 changes: 19 additions & 10 deletions br_nfe/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@


class ResCompany(models.Model):
_inherit = 'res.company'
_inherit = "res.company"

tipo_ambiente = fields.Selection([('1', u'Produção'),
('2', u'Homologação')],
string="Ambiente NFe", default='2')
tipo_ambiente = fields.Selection(
[("1", u"Produção"), ("2", u"Homologação")],
string="Ambiente NFe",
default="2",
)

cabecalho_danfe = fields.Selection([('vertical', 'Modelo Vertical'),
('horizontal', 'Modelo Horizontal')],
string=u"Cabeçalho Danfe",
default='vertical')
cabecalho_danfe = fields.Selection(
[
("vertical", "Modelo Vertical"),
("horizontal", "Modelo Horizontal"),
],
string=u"Cabeçalho Danfe",
default="vertical",
)
# NFC-e
id_token_csc = fields.Char(string="Identificador do CSC")
csc = fields.Char(string=u'Código de Segurança do Contribuinte')
csc = fields.Char(string=u"Código de Segurança do Contribuinte")
nfe_sinc = fields.Boolean(string="Aceita envio síncrono")

# Responsavel Técnico
id_token_csrt = fields.Char(string="Identificador do Responsavel Técnico")
csrt = fields.Char(string=u'Código de Segurança do Responsavel Técnico')
csrt = fields.Char(string=u"Código de Segurança do Responsavel Técnico")
responsavel_tecnico_id = fields.Many2one(
string="Responsável Técnico",
comodel_name="res.partner")
37 changes: 26 additions & 11 deletions br_nfe/views/res_company.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,32 @@
<record id="view_br_nfe_form" model="ir.ui.view">
<field name="name">br_account_nfe.res.company.form</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="br_base.view_company_form_inherited"/>
<field name="inherit_id" ref="br_base.view_company_form_inherited" />
<field name="arch" type="xml">
<field name="nfe_a1_password" position="after" >
<field name="id_token_csc" />
<field name="csc" />
<field name="tipo_ambiente" />
<field name="nfe_sinc"/>
<field name="cabecalho_danfe" />
<field name="id_token_csrt" />
<field name="csrt" />
</field>
<notebook position="inside">
<page name="nfe_nfce" string="NF-e/NFC-e">
<group>
<group name="nfce" string="NFC-e">
<field name="id_token_csc" />
<field name="csc" />
</group>
<group name="nfe" string="NF-e">
<field name="cabecalho_danfe" />
</group>
</group>
<group name="general" string="Geral">
<group name="envio" string="Envio">
<field name="tipo_ambiente" />
<field name="nfe_sinc" />
</group>
<group name="csrt" string="Responsável Técnico">
<field name="responsavel_tecnico_id"/>
<field name="id_token_csrt" string="Identificador do CRST"/>
<field name="csrt" string="CRST"/>
</group>
</group>
</page>
</notebook>
</field>
</record>
</odoo>
</odoo>
1 change: 1 addition & 0 deletions br_nfse_paulistana/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ def _prepare_edoc_item_vals(self, line):
res = super(AccountInvoice, self)._prepare_edoc_item_vals(line)
res['codigo_servico_paulistana'] = \
line.service_type_id.codigo_servico_paulistana
res['codigo_servico_paulistana_nome'] = line.service_type_id.name
return res
2 changes: 2 additions & 0 deletions br_nfse_paulistana/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class InvoiceEletronicItem(models.Model):

codigo_servico_paulistana = fields.Char(
string='Código NFSe Paulistana', size=5, readonly=True, states=STATE)
codigo_servico_paulistana_nome = fields.Char(
string='Descrição código NFSe Paulistana', readonly=True, states=STATE)


class InvoiceEletronic(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion br_nfse_paulistana/reports/danfse_sao_paulo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
Código do serviço:
<br />
<strong t-field="doc.eletronic_item_ids[0].codigo_servico_paulistana"></strong> -
<strong t-field="doc.eletronic_item_ids[0].product_id.service_type_id.name"></strong>
<strong t-field="doc.eletronic_item_ids[0].codigo_servico_paulistana_nome"></strong>
</div>
</div>
<div class="row" style="border: 1px solid black;">
Expand Down
4 changes: 0 additions & 4 deletions br_payment_cnab/views/account_journal_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
<div>
<field name="l10n_br_sequence_nosso_numero" />
</div>
<label for="l10n_br_sequence_statements" string="Seq. Retorno"/>
<div>
<field name="l10n_br_sequence_statements" />
</div>
</field>
</field>
</record>
Expand Down
4 changes: 2 additions & 2 deletions br_purchase/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _prepare_invoice_line_from_po_line(self, line):
res['tax_ii_id'] = ii and ii.id or False
res['tax_issqn_id'] = issqn and issqn.id or False
res['tax_csll_id'] = csll and csll.id or False
res['tax_irrf_id'] = inss and inss.id or False
res['tax_inss_id'] = irrf and irrf.id or False
res['tax_irrf_id'] = irrf and irrf.id or False
res['tax_inss_id'] = inss and inss.id or False

res['fiscal_position_type'] = line.fiscal_position_type
res['product_type'] = line.product_id.fiscal_type
Expand Down

0 comments on commit 926b4f9

Please sign in to comment.