-
invoice_line_ids
-
company_id
-
company_id.l10n_in_hsn_code_digit
-
l10n_in_hsn_code
|
def build_warning(record, action_name, message, views, domain=False):
return {
'message': message,
'action_text': self.env._("View %s", action_name),
'action': record._get_records_action(name=self.env._("Check %s", action_name), target='current', views=views, domain=domain or [])
}
indian_invoice = self.filtered(lambda m: m.country_code == 'IN' and m.move_type != 'entry')
for move in indian_invoice:
filtered_lines = move.invoice_line_ids.filtered(lambda line: line.display_type == 'product' and line.tax_ids and line._origin)
if move.company_id.l10n_in_hsn_code_digit and filtered_lines:
lines = self.env['account.move.line']
for line in filtered_lines:
if (line.l10n_in_hsn_code and (not re.match(r'^\d{4}$|^\d{6}$|^\d{8}$', line.l10n_in_hsn_code) or len(line.l10n_in_hsn_code) < int(move.company_id.l10n_in_hsn_code_digit))) or not line.l10n_in_hsn_code:
lines |= line._origin
digit_suffixes = {
'4': _("4 digits, 6 digits or 8 digits"),
'6': _("6 digits or 8 digits"),
'8': _("8 digits")
}
msg = _("Ensure that the HSN/SAC Code consists either %s in invoice lines",
digit_suffixes.get(move.company_id.l10n_in_hsn_code_digit, _("Invalid HSN/SAC Code digit"))
)
move.l10n_in_warning = {
'invalid_hsn_code_length': build_warning(
message=msg,
action_name=_("Journal Items(s)"),
record=lines,
views=[(self.env.ref("l10n_in.view_move_line_tree_hsn_l10n_in").id, "list")],
domain=[('id', 'in', lines.ids)]
)
} if lines else {}
else:
move.l10n_in_warning = {}
(self - indian_invoice).l10n_in_warning = {}
|
|