Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Created August 29, 2018 18:01
Show Gist options
  • Select an option

  • Save rvalyi/c1a081130b8e608d72fded14ef0f7420 to your computer and use it in GitHub Desktop.

Select an option

Save rvalyi/c1a081130b8e608d72fded14ef0f7420 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from odoo import fields, models, api
#from . import leiauteNFe as nfe
from spec_models import StackedModel
#from odoo.addons.l10n_br_nfe.models.v3_10 import leiauteNFe
# overriden to deal with conditional visibility and
# forcing to stack some optional taxes for usability consistency
# TODO inherit key ICMS classes to add a staking prefix and avoid collisions
class imposto(models.AbstractModel):
_inherit = 'nfe.v3_10.imposto'
# the following is a redefinition of conditional fields
# because generateDS won't manage these ones properly
nfe_choice10 = fields.Selection([
('icms_ipi_ii', 'ICMS-IPI-II'),
('issqn_ipi', 'ISSQN-IPI')],
"ICMS-IPI-II ou ISSQN-IPI",
default="icms_ipi_ii")
nfe_ICMS = fields.Many2one(
"nfe.v3_10.icms",
choice='10',
xsd_required=True,
view_attrs={'invisible':[('nfe_choice10','!=','icms_ipi_ii')]})
nfe_II = fields.Many2one(
"nfe.v3_10.ii",
choice='10',
view_attrs={'invisible':[('nfe_choice10','!=','icms_ipi_ii')]})
nfe_IPI = fields.Many2one(
"nfe.v3_10.tipi",
choice='10',
view_attrs='') # visible in both choices
nfe_ISSQN = fields.Many2one(
"nfe.v3_10.issqn",
choice='10',
xsd_required=True,
view_attrs={'invisible':[('nfe_choice10','!=','issqn_ipi')]})
nfe_PIS = fields.Many2one(
"nfe.v3_10.pis",
string="Dados do PIS",
stacked=True)
nfe_PISST = fields.Many2one(
"nfe.v3_10.pisst",
stacked=True,
string="Dados do PIS ST")
nfe_COFINS = fields.Many2one(
"nfe.v3_10.cofins",
stacked=True)
nfe_COFINSST = fields.Many2one(
"nfe.v3_10.cofinsst",
stacked=True,
string="Dados do COFINS da ST")
nfe_ICMSUFDest = fields.Many2one(
"nfe.v3_10.icmsufdest",
stacked=True)
class ResPartner(StackedModel):
# TODO inherit these abstract models before and make their fields computed
# TODO add field prefix in these classes to avoid field collision
# from Odoo l10n_br_base module.
# NOTE TODO
# dest has a m2o tendereco. tlocal and tendereco are really similar...
# what happen to m2o to tendereco if we don't inherit from tendereco?
# should we stack tendereco from dest? will m2o to tendereco work?
# can we use related fields and context views to avoid troubles?
_inherit = ["res.partner", "nfe.v3_10.dest", "nfe.v3_10.tendereco", "nfe.v3_10.tlocal", "nfe.v3_10.tenderemi"]
_name = "res.partner"
class ResCompany(StackedModel):
_inherit = ['res.company', 'nfe.v3_10.emit']
_name = "res.company"
nfe_enderEmit = fields.Many2one("res.partner", related='partner_id')
class FleetVehicle(StackedModel):
_inherit = ["fleet.vehicle", "nfe.v3_10.veicprod"]
_name = "fleet.vehicle"
class AccountInvoice(StackedModel, models.Model):
_inherit = ["account.invoice", "nfe.v3_10.infnfe"]
_name = "account.invoice"
_stacked = 'nfe.v3_10.infnfe'
_concrete_skip = ('nfe.v3_10.det',) # will be mixed in later
nfe_emit = fields.Many2one("res.company", related='company_id')
nfe_dest = fields.Many2one("res.partner", related='partner_id')
class AccountInvoiceLine(StackedModel):
_inherit = ["account.invoice.line", "nfe.v3_10.det"]
_name = "account.invoice.line"
_stacked = 'nfe.v3_10.det'
@api.one
@api.depends('sequence')
def _compute_nitem(self):
self.nfe_nItem = str(self.sequence or 0)
@api.model
def _default_nitem(self):
return '-'
nfe_xProd = fields.Text(string='Nome',
related='name', readonly=True)
nfe_NCM = fields.Char(string='NCM',
related='product_id.categ_id.name', readonly=True) # TODO real NCM
nfe_veicProd = fields.Many2one('fleet.vehicle')
nfe_nItem = fields.Char('Numero da Linha', compute='_compute_nitem', default=_default_nitem)
# automatic label is too long...
nfe_choice11 = fields.Selection(string="Tipo de ICMS")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment