Debian Codegraph @

addons/l10n_in_edi/models/account_move_line.py

raw
1 from odoo import models
2
3
4 class AccountMoveLine(models.Model):
5 _inherit = 'account.move.line'
6
7 # E-Invoice Methods
8 def _l10n_in_is_global_discount(self):
9 self.ensure_one()
10 return not self.tax_ids and self.price_subtotal < 0
11
12 def _l10n_in_check_einvoice_validation(self):
13 _ = self.env._
14 error_messages = {
15 'invalid_hsn': _(
16 "Missing or invalid HSN/SAC code: Ensure that invoice lines contain "
17 "4, 6 or 8 digits"
18 ),
19 'restrict_negative_discount_line': _("Negative discount is not allowed"),
20 'tax_validation': _(
21 "Set an appropriate GST tax on invoice lines "
22 "(if it's zero rated or nil rated then apply it too)"
23 ),
24 }
25
26 error_lines = {}
27 for line in self:
28 error_codes = []
29 if line.display_type != 'product' or line._l10n_in_is_global_discount():
30 continue
31 if line._l10n_in_check_invalid_hsn_code():
32 error_codes.append('invalid_hsn')
33 if line.discount < 0:
34 error_codes.append('restrict_negative_discount_line')
35 if not any(tax.l10n_in_tax_type in ['gst', 'nil_rated', 'exempt', 'non_gst'] for tax in line.tax_ids.flatten_taxes_hierarchy()):
36 error_codes.append('tax_validation')
37 for code in error_codes:
38 error_lines[code] = error_lines.get(code, self.env['account.move.line']) | line
39
40 return {
41 f"l10n_in_edi_{error_code}": {
42 'level': 'danger' if error_code == 'invalid_hsn' else 'warning',
43 'message': error_messages[error_code],
44 'action_text': _("View Invoice Line(s)"),
45 # The context are set in view_move_line_tree_hsn_l10n_in
46 # Please make sure to change, if any change in error codes
47 'action': lines.with_context(**{
48 error_code: True,
49 'send_and_print': True
50 })._get_records_action(
51 name=_("Check Invoice Line(s)"),
52 domain=[('id', 'in', lines.ids)],
53 views=[(
54 self.env.ref('l10n_in.view_move_line_tree_hsn_l10n_in').id,
55 'list'
56 )],
57 ),
58 }
59 for error_code, lines in error_lines.items()
60 }