Debian Codegraph @

addons/l10n_tr_nilvera_einvoice_extended/models/account_move_send.py

raw symbols SCIP
1 from odoo import _, models
2
3
4 class AccountMoveSend(models.AbstractModel):
5 _inherit = "account.move.send"
6
7 # -------------------------------------------------------------------------
8 # ALERTS
9 # -------------------------------------------------------------------------
10
11 def _get_alerts(self, moves, moves_data):
12 # EXTENDS 'account'
13 alerts = super()._get_alerts(moves, moves_data)
14 tr_moves = moves.filtered(lambda m: m.country_code == "TR")
15
16 # Warning alert if product is missing CTSP Number
17 if non_eligible_tr_products := tr_moves.invoice_line_ids.product_id.filtered(
18 lambda p: not p.l10n_tr_ctsp_number and "TR" in p.fiscal_country_codes,
19 ):
20 alerts["l10n_tr_non_eligible_products"] = {
21 "message": _(
22 "The following products are missing a CTSP Number:\n%(products)s\n",
23 products="\n".join(f"- {product.display_name}" for product in non_eligible_tr_products),
24 ),
25 "level": "warning",
26 "action_text": _("View Product(s)"),
27 "action": non_eligible_tr_products._get_records_action(
28 name=_("Check Products"),
29 ),
30 }
31 return alerts
32
33 def _get_l10n_tr_tax_partner_tax_office_alert(self, moves):
34 # OVERRIDES l10n_tr_nilvera_einvoice.
35 if tr_einvoice_partners_missing_ref := moves.partner_id.filtered(
36 lambda p: p.l10n_tr_nilvera_customer_status == "einvoice" and not p.l10n_tr_tax_office_id,
37 ):
38 return {
39 "message": _("The Tax Office is not set on the following TR Partner(s)."),
40 "action_text": _("View Partner(s)"),
41 "action": tr_einvoice_partners_missing_ref._get_records_action(
42 name=_("Check reference on Partner(s)"),
43 ),
44 "level": "danger",
45 }
46 return {}
47
48 def _get_l10n_tr_tax_company_tax_office_alert(self, moves):
49 # OVERRIDES l10n_tr_nilvera_einvoice.
50 if tr_companies_missing_tax_office := moves.company_id.filtered(
51 lambda c: (not c.l10n_tr_tax_office_id and c.country_code == "TR"),
52 ):
53 return {
54 "message": _("The Tax Office is not set on the following TR Company(s)."),
55 "action_text": _("View Company(s)"),
56 "action": tr_companies_missing_tax_office._get_records_action(
57 name=_(" TR Company(s)"),
58 ),
59 "level": "danger",
60 }
61 return {}
62
63 def _get_l10n_tr_tax_partner_address_alert(self, moves):
64 # EXTENDS l10n_tr_nilvera_einvoice.
65 return super()._get_l10n_tr_tax_partner_address_alert(moves.filtered(lambda move: not move.l10n_tr_is_export_invoice))