perf(account.invoice): integracion con base_cfdi_mixin

se usa el modelo base_cfdi_mixin para tratar lo relacionado con los CFDI
se modifica la vista, para la integracion con base_cfdi_mixin
parent 871c2617
......@@ -23,7 +23,11 @@ _logger = logging.getLogger(__name__)
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
_name = 'account.invoice'
_inherit = [
'account.invoice',
'base.cfdi',
]
@api.model
def _default_address_issued_id(self):
......@@ -179,13 +183,6 @@ class AccountInvoice(models.Model):
'cfdi.use', 'CFDI use',
readonly=True, states={'draft': [('readonly', False)]},
)
cfdi_id = fields.Many2one(
'ir.attachment.facturae.mx', 'CFDI', compute='_compute_cfdi_id',
)
cfdi_folio_fiscal = fields.Char(
'CFD-I Folio Fiscal', compute='_compute_cfdi_folio_fiscal',
help='Folio used in the electronic invoice',
)
cfdi_adenda_id = fields.Many2one(
'cfdi.adenda', 'Addendum',
help='Select addendum node to use on invoice.',
......@@ -212,25 +209,6 @@ class AccountInvoice(models.Model):
)
self.datetime = invoice_datetime
@api.one
def _compute_cfdi_id(self):
ir_attachment_mx_obj = self.env['ir.attachment.facturae.mx']
related_attachment = ir_attachment_mx_obj.search(
[
('res_id', '=', self.id),
('type_attachment', '=', 'account.invoice'),
('company_id', '=', self.company_id.id),
('state', 'in', ['signed', 'done']),
],
)
if related_attachment:
self.cfdi_id = related_attachment
@api.one
@api.depends('state')
def _compute_cfdi_folio_fiscal(self):
self.cfdi_folio_fiscal = self.cfdi_id.uuid
def onchange_partner_id(
self, cr, uid, ids, type, partner_id,
date_invoice=False, payment_term=False, partner_bank_id=False,
......@@ -279,27 +257,17 @@ class AccountInvoice(models.Model):
@signals.invoice_validate.connect
def sign_invoice_sat(self, cr, uid, ids, context=None):
context = dict(context or {})
ir_attach_obj = self.pool.get('ir.attachment.facturae.mx')
for account_invoice in self.browse(cr, uid, ids, context=context):
if account_invoice.journal_id.sign_sat:
# Create new CFDI object for this invoice
cfdi_id = ir_attach_obj.create(
cr, uid,
{
'name': account_invoice.fname_invoice,
'res_id': account_invoice.id,
'type_attachment': 'account.invoice',
'company_id': account_invoice.company_id.id,
},
context=context,
)
cfdi = ir_attach_obj.browse(
cr, uid, cfdi_id, context=context,
)
cfdi.action_validate()
account_invoice.create_cfdi()
@api.multi
def action_cancel(self,):
def action_cancel(self):
'''
Extend `AccountInvoice.action_cancel()`; Cancels the CFDI related to the
invoice
'''
for account_invoice in self:
# Maybe a third test could review state, but since
# button cancel only is displayed in open state, we decided to not
......@@ -309,8 +277,14 @@ class AccountInvoice(models.Model):
account_invoice.journal_id.sign_sat and
account_invoice.cfdi_folio_fiscal
):
account_invoice.cfdi_id.action_cancel()
super(AccountInvoice, self).action_cancel()
cancelacion = account_invoice.cancel_cfdi()[0]
if cancelacion:
super(AccountInvoice, self).action_cancel()
account_invoice.unlink_cfdi()
return
account_invoice.write({
'state':account_invoice.cfdi_state,
})
@staticmethod
def _sanitize(text):
......
......@@ -13,7 +13,7 @@
<field name="arch" type="xml">
<xpath expr="//sheet[@string='Invoice']/h1" position="after">
<h4 collspan="2">
<field string="Fiscal Number" name="cfdi_folio_fiscal"
<field string="Fiscal Number" name="cfdi_id"
placeholder="Fiscal Number" readonly="1"/>
</h4>
</xpath>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment