Skip to content

Commit

Permalink
[FIX] force imported account move to have proper UOM
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Nov 14, 2023
1 parent 43e37d7 commit abae60d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,7 @@ def import_fiscal_document(
line_form.fiscal_operation_id = self.fiscal_operation_id
line_form.fiscal_document_line_id = line
move_form.save()
move = self.env["account.move"].browse(move_form.id)

Check warning on line 857 in l10n_br_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/account_move.py#L854-L857

Added lines #L854 - L857 were not covered by tests
for line in move.invoice_line_ids:
line.product_uom_id = line.fiscal_document_line_id.uom_id.id
return move_form

Check warning on line 860 in l10n_br_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/account_move.py#L859-L860

Added lines #L859 - L860 were not covered by tests
7 changes: 5 additions & 2 deletions l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ def _onchange_fiscal_document_line_id(self):
setattr(self, field, value[0])

Check warning on line 499 in l10n_br_account/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/account_move_line.py#L499

Added line #L499 was not covered by tests
else:
setattr(self, field, value)
# override the default product uom (set by the onchange):
self.product_uom_id = self.fiscal_document_line_id.uom_id.id

@api.onchange("fiscal_tax_ids")
def _onchange_fiscal_tax_ids(self):
Expand Down Expand Up @@ -676,3 +674,8 @@ def _get_amount_credit_debit_model(
"debit": balance > 0.0 and balance or 0.0,
"credit": balance < 0.0 and -balance or 0.0,
}

@api.constrains("product_uom_id")
def _check_product_uom_category_id(self):
not_imported = self.filtered(lambda line: not line._is_imported())
return super(AccountMoveLine, not_imported)._check_product_uom_category_id()

0 comments on commit abae60d

Please sign in to comment.