| 1 |
from odoo import _, api, fields, models |
| 2 |
from odoo.exceptions import UserError |
| 3 |
|
| 4 |
|
| 5 |
class AccountMove(models.Model): |
| 6 |
_inherit = 'account.move' |
| 7 |
|
| 8 |
nemhandel_message_uuid = fields.Char(string='Nemhandel message ID', copy=False) |
| 9 |
nemhandel_move_state = fields.Selection( |
| 10 |
selection=[ |
| 11 |
('ready', 'Ready to send'), |
| 12 |
('to_send', 'Queued'), |
| 13 |
('processing', 'Pending Reception'), |
| 14 |
('done', 'Done'), |
| 15 |
('error', 'Error'), |
| 16 |
], |
| 17 |
compute='_compute_nemhandel_move_state', |
| 18 |
store=True, |
| 19 |
string='Nemhandel status', |
| 20 |
copy=False, |
| 21 |
) |
| 22 |
|
| 23 |
@api.depends('state') |
| 24 |
def _compute_nemhandel_move_state(self): |
| 25 |
for move in self: |
| 26 |
if all([ |
| 27 |
move.company_id.l10n_dk_nemhandel_proxy_state == 'receiver', |
| 28 |
move.commercial_partner_id.nemhandel_verification_state == 'valid', |
| 29 |
move.state == 'posted', |
| 30 |
move.is_sale_document(include_receipts=True), |
| 31 |
not move.nemhandel_move_state, |
| 32 |
]): |
| 33 |
move.nemhandel_move_state = 'ready' |
| 34 |
elif ( |
| 35 |
move.state == 'draft' |
| 36 |
and move.is_sale_document(include_receipts=True) |
| 37 |
and move.nemhandel_move_state not in {'processing', 'done'} |
| 38 |
): |
| 39 |
move.nemhandel_move_state = False |
| 40 |
else: |
| 41 |
move.nemhandel_move_state = move.nemhandel_move_state |
| 42 |
|
| 43 |
@api.model |
| 44 |
def _get_ubl_cii_builder_from_xml_tree(self, tree): |
| 45 |
# Deprecated |
| 46 |
# Extends account_edi_ubl_cii |
| 47 |
customization_id = tree.find('{*}CustomizationID') |
| 48 |
if customization_id is not None and 'OIOUBL-2' in customization_id.text: |
| 49 |
return self.env['account.edi.xml.oioubl_21'] |
| 50 |
return super()._get_ubl_cii_builder_from_xml_tree(tree) |
| 51 |
|
| 52 |
def _get_import_file_type(self, file_data): |
| 53 |
""" Identify OIOUBL files. """ |
| 54 |
# EXTENDS 'account' |
| 55 |
if ( |
| 56 |
file_data['xml_tree'] is not None |
| 57 |
and (customization_id := file_data['xml_tree'].findtext('{*}CustomizationID')) |
| 58 |
and customization_id == 'OIOUBL-2.1' |
| 59 |
): |
| 60 |
return 'account.edi.xml.oioubl_21' |
| 61 |
|
| 62 |
return super()._get_import_file_type(file_data) |
| 63 |
|
| 64 |
def action_cancel_nemhandel_documents(self): |
| 65 |
# if the nemhandel_move_state is processing/done |
| 66 |
# then it means it has been already sent to nemhandel proxy and we can't cancel |
| 67 |
if any(move.nemhandel_move_state in {'processing', 'done'} for move in self): |
| 68 |
raise UserError(_("Cannot cancel an entry that has already been sent to Nemhandel")) |
| 69 |
self.nemhandel_move_state = False |
| 70 |
self.sending_data = False |
| 71 |
|
| 72 |
def action_send_and_print(self): |
| 73 |
for move in self: |
| 74 |
move.commercial_partner_id.button_nemhandel_check_partner_endpoint(company=move.company_id) |
| 75 |
return super().action_send_and_print() |