Debian Codegraph @

addons/l10n_dk_nemhandel/wizard/account_move_send_wizard.py

raw
1 from odoo import _, models
2 from odoo.exceptions import UserError
3
4
5 class AccountMoveSendWizard(models.TransientModel):
6 _inherit = 'account.move.send.wizard'
7
8 # -------------------------------------------------------------------------
9 # DEFAULTS
10 # -------------------------------------------------------------------------
11
12 def _compute_sending_method_checkboxes(self):
13 """ EXTENDS 'account'
14 If Customer is not valid on Nemhandel, we disable the checkbox. Also add the proxy mode if not in prod.
15 """
16 super()._compute_sending_method_checkboxes()
17 for wizard in self:
18 nemhandel_checkbox = wizard.sending_method_checkboxes.get('nemhandel')
19 if not nemhandel_checkbox:
20 continue
21
22 nemhandel_partner = wizard.move_id.partner_id.commercial_partner_id.with_company(wizard.company_id)
23 nemhandel_proxy_mode = wizard.company_id._get_nemhandel_edi_mode()
24 if nemhandel_partner.nemhandel_verification_state == 'not_valid':
25 addendum_disable_reason = _(' (Customer not on Nemhandel)')
26 elif nemhandel_partner.nemhandel_verification_state == 'not_verified':
27 addendum_disable_reason = _(' (no VAT)')
28 else:
29 addendum_disable_reason = ''
30 vals_not_valid = {'readonly': True, 'checked': False} if addendum_disable_reason else {}
31 addendum_mode = ''
32 if nemhandel_proxy_mode == 'test':
33 addendum_mode = _(' (Test)')
34 elif nemhandel_proxy_mode == 'demo':
35 addendum_mode = _(' (Demo)')
36 if addendum_disable_reason or addendum_mode:
37 wizard.sending_method_checkboxes = {
38 **wizard.sending_method_checkboxes,
39 'nemhandel': {
40 **nemhandel_checkbox,
41 **vals_not_valid,
42 'label': f"{nemhandel_checkbox['label']}{addendum_disable_reason}{addendum_mode}",
43 },
44 }
45
46 def action_send_and_print(self, allow_fallback_pdf=False):
47 # EXTENDS 'account'
48 self.ensure_one()
49 if self.sending_methods and 'nemhandel' in self.sending_methods:
50 move = self.move_id.with_company(self.move_id.company_id)
51 if move.partner_id.commercial_partner_id.nemhandel_verification_state != 'valid':
52 raise UserError(_("Partner doesn't have a valid Nemhandel configuration."))
53
54 move.nemhandel_move_state = 'to_send'
55 return super().action_send_and_print(allow_fallback_pdf=allow_fallback_pdf)