se extraen tipo_responsabilidad/tipo_organizacion a tipo aparte
This commit is contained in:
parent
80ec627f98
commit
96a9a0bf76
|
@ -16,6 +16,8 @@ def register():
|
||||||
invoice.Invoice,
|
invoice.Invoice,
|
||||||
invoice.InvoiceLine,
|
invoice.InvoiceLine,
|
||||||
invoice.Product,
|
invoice.Product,
|
||||||
|
invoice.PartyFeIdentifier,
|
||||||
|
invoice.PartyFeOrganization,
|
||||||
invoice.Party,
|
invoice.Party,
|
||||||
invoice.Cron,
|
invoice.Cron,
|
||||||
dian.RangoFacturacion,
|
dian.RangoFacturacion,
|
||||||
|
|
99
invoice.py
99
invoice.py
|
@ -1,4 +1,4 @@
|
||||||
from trytond.model import fields, ModelView
|
from trytond.model import fields, ModelView, ModelSQL
|
||||||
from trytond.pool import PoolMeta, Pool
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
|
@ -10,6 +10,8 @@ from facho import fe
|
||||||
from facho.fe.client import dian
|
from facho.fe.client import dian
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Cron(metaclass=PoolMeta):
|
class Cron(metaclass=PoolMeta):
|
||||||
__name__ = 'ir.cron'
|
__name__ = 'ir.cron'
|
||||||
|
@ -21,35 +23,82 @@ class Cron(metaclass=PoolMeta):
|
||||||
('account.invoice|fe_delivery', 'FE Delivery')
|
('account.invoice|fe_delivery', 'FE Delivery')
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class Party(metaclass=PoolMeta):
|
class Party(metaclass=PoolMeta):
|
||||||
__name__ = 'party.party'
|
__name__ = 'party.party'
|
||||||
|
|
||||||
fe_tipo_responsabilidad = fields.Many2One('account_invoice_facho.fe_generic_code',
|
fe_identifiers = fields.One2Many('account_invoice_facho.party.fe_identifier',
|
||||||
'Tipo Responsabilidad',
|
'party', 'Fe Identifiers', required=True)
|
||||||
domain=[('resource', '=', 'tipo_responsabilidad')],
|
fe_organizations = fields.One2Many('account_invoice_facho.party.fe_organization',
|
||||||
required=True)
|
'party', 'Fe Organizations', required=True)
|
||||||
fe_tipo_organizacion = fields.Many2One('account_invoice_facho.fe_generic_code',
|
|
||||||
'Tipo Organizacion',
|
|
||||||
domain=[('resource', '=', 'tipo_organizacion')],
|
|
||||||
required=True)
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fe_identifier(self):
|
||||||
|
try:
|
||||||
|
return self.fe_identifiers[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fe_organization(self):
|
||||||
|
try:
|
||||||
|
return self.fe_organizations[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
def tofacho(self):
|
def tofacho(self):
|
||||||
|
tax_identifier = self.tax_identifer
|
||||||
|
if tax_identifer is None:
|
||||||
|
tax_identifer = ''
|
||||||
return form.Party(
|
return form.Party(
|
||||||
name = self.name,
|
name = self.name,
|
||||||
ident = self.name, # TODO
|
ident = tax_identifer,
|
||||||
responsability_code = self.fe_tipo_responsabilidad.code,
|
responsability_code = self.fe_identifier.fe_code,
|
||||||
organization_code = self.fe_tipo_organizacion.code,
|
organization_code = self.fe_organization.fe_code,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PartyFeOrganization(ModelSQL, ModelView):
|
||||||
|
'Party Facturacion Electronica Organizacion'
|
||||||
|
__name__ = 'account_invoice_facho.party.fe_organization'
|
||||||
|
|
||||||
|
name = fields.Char('Name', required=True)
|
||||||
|
party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
|
||||||
|
required=True, select=True)
|
||||||
|
fe_tipo = fields.Many2One('account_invoice_facho.fe_generic_code',
|
||||||
|
'Tipo Organizacion',
|
||||||
|
domain=[('resource', '=', 'tipo_organizacion')],
|
||||||
|
required=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fe_code(self):
|
||||||
|
return self.fe_tipo.code
|
||||||
|
|
||||||
|
|
||||||
|
class PartyFeIdentifier(ModelSQL, ModelView):
|
||||||
|
'Party Facturaction Electron Identificador'
|
||||||
|
__name__ = 'account_invoice_facho.party.fe_identifier'
|
||||||
|
_rec_name = 'code'
|
||||||
|
code = fields.Char('Code', required=True)
|
||||||
|
party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
|
||||||
|
required=True, select=True)
|
||||||
|
fe_tipo = fields.Many2One('account_invoice_facho.fe_generic_code',
|
||||||
|
'Tipo Responsabilidad',
|
||||||
|
domain=[('resource', '=', 'tipo_responsabilidad')],
|
||||||
|
required=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fe_code(self):
|
||||||
|
return self.fe_tipo.code
|
||||||
|
|
||||||
|
|
||||||
class Invoice(metaclass=PoolMeta):
|
class Invoice(metaclass=PoolMeta):
|
||||||
__name__ = 'account.invoice'
|
__name__ = 'account.invoice'
|
||||||
|
|
||||||
_states = {'invisible': ~Eval('is_fe_colombia', False)}
|
_states = {'invisible': ~Eval('is_fe_colombia', False),
|
||||||
|
'readonly': Eval('state') != 'draft'}
|
||||||
_depends = ['is_fe_colombia']
|
_states_readonly = {'readonly': Eval('state') != 'draft'}
|
||||||
|
_depends = ['is_fe_colombia', 'state']
|
||||||
|
|
||||||
is_fe_colombia = fields.Boolean('FE Colombia?',
|
is_fe_colombia = fields.Boolean('FE Colombia?',
|
||||||
states={'invisible': False})
|
states={'invisible': False})
|
||||||
|
@ -63,14 +112,18 @@ class Invoice(metaclass=PoolMeta):
|
||||||
('exception', 'Exception'), # local exception
|
('exception', 'Exception'), # local exception
|
||||||
('failure', 'Failure'), # remoto fallo
|
('failure', 'Failure'), # remoto fallo
|
||||||
('done', 'Done') # remoto ok
|
('done', 'Done') # remoto ok
|
||||||
], 'Delivery State', states=_states, depends=_depends)
|
], 'Delivery State', states=_states_readonly, depends=_depends)
|
||||||
fe_delivery_trackid = fields.Char('Delivery TrackID',
|
fe_delivery_trackid = fields.Char('Delivery TrackID',
|
||||||
states=_states,
|
states=_states_readonly,
|
||||||
depends=_depends)
|
depends=_depends)
|
||||||
fe_delivery_status = fields.Text('Delivery Status',
|
fe_delivery_status = fields.Text('Delivery Status',
|
||||||
states=_states,
|
states=_states_readonly,
|
||||||
depends=_depends)
|
depends=_depends)
|
||||||
del _states
|
fe_delivery_checked_at = fields.DateTime('Delivery Checked At',
|
||||||
|
states=_states_readonly,
|
||||||
|
depends=_depends)
|
||||||
|
|
||||||
|
del _states, _states_readonly
|
||||||
del _depends
|
del _depends
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -137,9 +190,9 @@ class Invoice(metaclass=PoolMeta):
|
||||||
|
|
||||||
def _force_write(self, params):
|
def _force_write(self, params):
|
||||||
self.state = 'draft'
|
self.state = 'draft'
|
||||||
|
params['fe_delivery_checked_at'] = datetime.now()
|
||||||
self.write([self], params)
|
self.write([self], params)
|
||||||
|
|
||||||
|
|
||||||
def fe_delivery_test(self):
|
def fe_delivery_test(self):
|
||||||
config = Pool().get('account_invoice_facho.configuration')(1)
|
config = Pool().get('account_invoice_facho.configuration')(1)
|
||||||
if self.fe_delivery_state not in ['queued', 'draft']:
|
if self.fe_delivery_state not in ['queued', 'draft']:
|
||||||
|
@ -161,11 +214,9 @@ class Invoice(metaclass=PoolMeta):
|
||||||
))
|
))
|
||||||
if not res.ZipKey:
|
if not res.ZipKey:
|
||||||
raise UserError(str(res))
|
raise UserError(str(res))
|
||||||
# HACK force draft for allow write
|
|
||||||
self._force_write({'fe_delivery_state': 'delivered',
|
self._force_write({'fe_delivery_state': 'delivered',
|
||||||
'fe_delivery_trackid': res.ZipKey})
|
'fe_delivery_trackid': res.ZipKey})
|
||||||
|
|
||||||
|
|
||||||
def fe_process(self):
|
def fe_process(self):
|
||||||
if self.fe_habilitacion:
|
if self.fe_habilitacion:
|
||||||
# TODO forzar facturas contabilidadas
|
# TODO forzar facturas contabilidadas
|
||||||
|
@ -176,7 +227,7 @@ class Invoice(metaclass=PoolMeta):
|
||||||
for inv in cls.search([('is_fe_colombia', '=', True),
|
for inv in cls.search([('is_fe_colombia', '=', True),
|
||||||
('state', 'in', ['posted', 'paid'])]):
|
('state', 'in', ['posted', 'paid'])]):
|
||||||
inv.fe_process()
|
inv.fe_process()
|
||||||
if inv.fe_delivery_state == 'delivered':
|
if inv.fe_delivery_state in ['delivered', 'failure']:
|
||||||
inv.fe_update_status()
|
inv.fe_update_status()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,15 @@
|
||||||
<page string="FE Colombia" name="fe_colombia">
|
<page string="FE Colombia" name="fe_colombia">
|
||||||
<label name="fe_delivery_state"/>
|
<label name="fe_delivery_state"/>
|
||||||
<field name="fe_delivery_state"/>
|
<field name="fe_delivery_state"/>
|
||||||
|
<newline/>
|
||||||
<label name="fe_delivery_status"/>
|
<label name="fe_delivery_status"/>
|
||||||
<field name="fe_delivery_status"/>
|
<field name="fe_delivery_status"/>
|
||||||
|
<newline/>
|
||||||
<label name="fe_delivery_trackid"/>
|
<label name="fe_delivery_trackid"/>
|
||||||
<field name="fe_delivery_trackid"/>
|
<field name="fe_delivery_trackid"/>
|
||||||
|
<newline/>
|
||||||
|
<label name="fe_delivery_checked_at"/>
|
||||||
|
<field name="fe_delivery_checked_at"/>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
<xpath expr="/form/notebook/page[@name='identifiers']"
|
<xpath expr="/form/notebook/page[@name='identifiers']"
|
||||||
position="after">
|
position="after">
|
||||||
<page string="FE Colombia" name="fe_colombia">
|
<page string="FE Colombia" name="fe_colombia">
|
||||||
<label name="fe_tipo_responsabilidad"/>
|
<field name="fe_identifiers"/>
|
||||||
<field name="fe_tipo_responsabilidad"/>
|
<field name="fe_organizations"/>
|
||||||
<label name="fe_tipo_organizacion"/>
|
|
||||||
<field name="fe_tipo_organizacion"/>
|
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue