Add more controls when going draft a sent invoice.
This commit refs #18019
This commit is contained in:
parent
b2d1e52c1e
commit
7a19d2925a
92
invoice.py
92
invoice.py
|
@ -273,11 +273,21 @@ class Invoice2(metaclass=PoolMeta):
|
|||
cls._sii_state_deny_draft = {
|
||||
'Correcto', 'Correcta', 'AceptadoConErrores', 'AceptadaConErrores'
|
||||
}
|
||||
cls._deny_modify_sii_fields = {'reference', 'party', 'invoice_date'}
|
||||
cls._error_messages.update({
|
||||
'draft_invalid_sii_state': ('You can not set to draft invoice '
|
||||
'"%(invoice)s" because the SII state is "%(sii_state)s". '
|
||||
'Please first include the invoice in a Delete Invoice SII '
|
||||
'Book and send to AEAT.')
|
||||
'deny_draft_invalid_sii_state':
|
||||
'You can not set to draft invoice "%(invoice)s" because the '
|
||||
'SII state is "%(sii_state)s". Please first include the '
|
||||
'invoice in a Delete Invoice SII Book and send to AEAT.',
|
||||
'modify_invalid_sii_state':
|
||||
'Invoice "%(invoice)s" was sent to SII and the state is '
|
||||
'"%(sii_state)s". Please remember after posting to send it '
|
||||
'again with a Modify SII Book.',
|
||||
'deny_modify_sii_pk':
|
||||
'Cannot modify "%(fields)s" on invoice "%(invoice)s" '
|
||||
'because its SII state is "%(sii_state)s". Please first '
|
||||
'include the invoice in a Delete Invoice SII Book and send '
|
||||
'to AEAT.'
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
@ -285,11 +295,71 @@ class Invoice2(metaclass=PoolMeta):
|
|||
@Workflow.transition('draft')
|
||||
def draft(cls, invoices):
|
||||
for invoice in invoices:
|
||||
if invoice.sii_state in cls._sii_state_deny_draft and \
|
||||
invoice.sii_communication_type != 'D0':
|
||||
cls.raise_user_error('draft_invalid_sii_state', {
|
||||
'invoice': invoice.rec_name,
|
||||
'sii_state': invoice.sii_state
|
||||
})
|
||||
|
||||
invoice.check_sent_sii()
|
||||
super().draft(invoices)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('posted')
|
||||
def post(cls, invoices):
|
||||
for invoice in invoices:
|
||||
if invoice.state in ('draft', 'validated'):
|
||||
invoice.check_sent_sii()
|
||||
super().post(invoices)
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
actions = iter(args)
|
||||
args = []
|
||||
for records, values in zip(actions, actions):
|
||||
sii_vals = set(values) & cls._deny_modify_sii_fields
|
||||
if sii_vals:
|
||||
for record in records:
|
||||
if record.type == 'in':
|
||||
record.check_sent_sii(list(sii_vals))
|
||||
args.extend((records, values))
|
||||
super().write(*args)
|
||||
|
||||
def check_sent_sii(self, fields=[]):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
User = pool.get('res.user')
|
||||
Group = pool.get('res.group')
|
||||
|
||||
if self.sii_state in self._sii_state_deny_draft and \
|
||||
self.sii_communication_type != 'D0':
|
||||
|
||||
# check group
|
||||
def in_group():
|
||||
group = Group(ModelData.get_id(
|
||||
'aeat_sii',
|
||||
'group_invoice_sent_sii_posted2draft'))
|
||||
transaction = Transaction()
|
||||
user_id = transaction.user
|
||||
if user_id == 0:
|
||||
user_id = transaction.context.get('user', user_id)
|
||||
if user_id == 0:
|
||||
return True
|
||||
user = User(user_id)
|
||||
return group in user.groups
|
||||
|
||||
if fields:
|
||||
self.raise_user_error('deny_modify_sii_pk', {
|
||||
'fields': ', '.join(
|
||||
[f['string'] for f in self.__class__.fields_get(
|
||||
fields_names=fields).values()]),
|
||||
'invoice': self.rec_name,
|
||||
'sii_state': self.sii_state
|
||||
})
|
||||
elif not in_group():
|
||||
self.raise_user_error('deny_draft_invalid_sii_state', {
|
||||
'invoice': self.rec_name,
|
||||
'sii_state': self.sii_state
|
||||
})
|
||||
else:
|
||||
self.raise_user_warning(
|
||||
'modify_invalid_sii_state_%s' % self.id,
|
||||
'modify_invalid_sii_state', {
|
||||
'invoice': self.rec_name,
|
||||
'sii_state': self.sii_state
|
||||
})
|
||||
|
|
15
invoice.xml
15
invoice.xml
|
@ -22,4 +22,19 @@
|
|||
<field name="model" search="[('model', '=', 'account.invoice')]"/>
|
||||
</record>
|
||||
</data>
|
||||
<data depends="account_invoice_posted2draft">
|
||||
<record model="res.group" id="group_invoice_sent_sii_posted2draft">
|
||||
<field name="name">Force Draft Account Invoice sent to SII</field>
|
||||
</record>
|
||||
<record model="res.user-res.group"
|
||||
id="user_admin_group_invoice_sent_sii_posted2draft">
|
||||
<field name="user" ref="res.user_admin"/>
|
||||
<field name="group" ref="group_invoice_sent_sii_posted2draft"/>
|
||||
</record>
|
||||
<record model="res.user-res.group"
|
||||
id="user_trigger_group_invoice_sent_sii_posted2draft">
|
||||
<field name="user" ref="res.user_trigger"/>
|
||||
<field name="group" ref="group_invoice_sent_sii_posted2draft"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
16
locale/es.po
16
locale/es.po
|
@ -24,6 +24,18 @@ msgid ""
|
|||
msgstr ""
|
||||
"No puede pasar a borrador la factura \"%(invoice)s\" porque su estado SII es \"%(sii_state)s\". Por favor incluya la factura en un libro SII de anulación de facturas y envíelo a la AEAT."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" was sent to SII and the state is \"%(sii_state)s\". Please remember after posting to send it again with a Modify SII Book."
|
||||
msgstr ""
|
||||
"La factura \"%(invoice)s\" fue enviada al SII y su estado es \"%(sii_state)s\". Por favor recuerde enviarla de nuevo a la AEAT en un libro SII de modificación de facturas tras contabilizarla."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Cannot modify \"%(fields)s\" on invoice \"%(invoice)s\" because its SII state is \"%(sii_state)s\". Please first include the invoice in a Delete Invoice SII Book and send to AEAT."
|
||||
msgstr ""
|
||||
"No puede modificar \"%(fields)s\" en la factura \"%(invoice)s\" porque su estado SII es \"%(sii_state)s\". Por favor incluya la factura en un libro SII de anulación de facturas y envíelo a la AEAT."
|
||||
|
||||
msgctxt "field:account.invoice,sii_book_key:"
|
||||
msgid "SII Book Key"
|
||||
msgstr "SII Clave libro"
|
||||
|
@ -1689,3 +1701,7 @@ msgstr "Cancelar"
|
|||
msgctxt "wizard_button:aeat.sii.load_pkcs12,start,load:"
|
||||
msgid "Load"
|
||||
msgstr "Cargar"
|
||||
|
||||
msgctxt "model:res.group,name:group_invoice_sent_sii_posted2draft"
|
||||
msgid "Force Draft Account Invoice sent to SII"
|
||||
msgstr "Forzar borrador factura enviada a SII"
|
Loading…
Reference in New Issue