| 1 |
from odoo import _, api, fields, models |
| 2 |
from odoo.exceptions import ValidationError |
| 3 |
|
| 4 |
from odoo.addons.l10n_dk_nemhandel.tools.demo_utils import handle_demo |
| 5 |
|
| 6 |
|
| 7 |
class ResConfigSettings(models.TransientModel): |
| 8 |
_inherit = 'res.config.settings' |
| 9 |
|
| 10 |
nemhandel_edi_user = fields.Many2one(related='company_id.nemhandel_edi_user') |
| 11 |
nemhandel_edi_mode = fields.Selection(string='Nemhandel EDI operating mode', related='nemhandel_edi_user.edi_mode') |
| 12 |
nemhandel_contact_email = fields.Char(related='company_id.nemhandel_contact_email', readonly=False) |
| 13 |
nemhandel_identifier_type = fields.Selection(related='company_id.nemhandel_identifier_type', readonly=False) |
| 14 |
nemhandel_identifier_value = fields.Char(related='company_id.nemhandel_identifier_value', readonly=False) |
| 15 |
nemhandel_edi_identification = fields.Char(string='Nemhandel identification', related='nemhandel_edi_user.edi_identification') |
| 16 |
nemhandel_phone_number = fields.Char(related='company_id.nemhandel_phone_number', readonly=False) |
| 17 |
l10n_dk_nemhandel_proxy_state = fields.Selection(related='company_id.l10n_dk_nemhandel_proxy_state', readonly=False) |
| 18 |
nemhandel_purchase_journal_id = fields.Many2one(related='company_id.nemhandel_purchase_journal_id', readonly=False) |
| 19 |
|
| 20 |
# ------------------------------------------------------------------------- |
| 21 |
# COMPUTE METHODS |
| 22 |
# ------------------------------------------------------------------------- |
| 23 |
|
| 24 |
@api.depends("company_id.account_edi_proxy_client_ids") |
| 25 |
def _compute_nemhandel_edi_user(self): |
| 26 |
for config in self: |
| 27 |
config.nemhandel_edi_user = config.company_id.account_edi_proxy_client_ids.filtered(lambda u: u.proxy_type == 'nemhandel') |
| 28 |
|
| 29 |
# ------------------------------------------------------------------------- |
| 30 |
# BUSINESS ACTIONS |
| 31 |
# ------------------------------------------------------------------------- |
| 32 |
|
| 33 |
def action_open_nemhandel_form(self): |
| 34 |
self.ensure_one() |
| 35 |
registration_wizard = self.env['nemhandel.registration'].create({'company_id': self.company_id.id}) |
| 36 |
registration_action = registration_wizard._action_open_nemhandel_form(reopen=False) |
| 37 |
return registration_action |
| 38 |
|
| 39 |
@handle_demo |
| 40 |
def button_update_nemhandel_user_data(self): |
| 41 |
""" |
| 42 |
Action for the user to be able to update their contact details any time |
| 43 |
Calls /update_user on the iap server |
| 44 |
""" |
| 45 |
self.ensure_one() |
| 46 |
|
| 47 |
if not self.nemhandel_contact_email: |
| 48 |
raise ValidationError(_("Contact email is required")) |
| 49 |
|
| 50 |
self.nemhandel_edi_user._call_nemhandel_proxy( |
| 51 |
endpoint='/api/nemhandel/1/update_user', |
| 52 |
params={ |
| 53 |
'update_data': { |
| 54 |
'nemhandel_contact_email': self.nemhandel_contact_email, |
| 55 |
}, |
| 56 |
}, |
| 57 |
) |
| 58 |
return True |
| 59 |
|
| 60 |
@handle_demo |
| 61 |
def button_deregister_nemhandel_participant(self): |
| 62 |
""" |
| 63 |
Deregister the edi user from Nemhandel network |
| 64 |
""" |
| 65 |
self.ensure_one() |
| 66 |
|
| 67 |
if self.nemhandel_edi_user: |
| 68 |
self.nemhandel_edi_user._nemhandel_deregister_participant() |
| 69 |
return True |