Skip to content

Commit

Permalink
[NEW][l10n_br_account] Create a.m. from after import edoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mileo committed Dec 18, 2024
1 parent 56c0fe2 commit d1a8056
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
69 changes: 36 additions & 33 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,39 +728,42 @@ def _get_integrity_hash_fields_and_subfields(self):
for subfield in self.env["account.move.line"]._get_integrity_hash_fields()
]

def button_import_fiscal_document(self):
"""
Import move fields and invoice lines from
the fiscal_document_id record if there is any new line
to import.
You can typically set fiscal_document_id to some l10n_br_fiscal.document
record that was imported previously and import its lines into the
current move.
"""
for move in self:
if move.state != "draft":
raise UserError(_("Cannot import in non draft Account Move!"))
elif (
move.partner_id
and move.partner_id != move.fiscal_document_id.partner_id
):
raise UserError(_("Partner mismatch!"))
elif (
MOVE_TO_OPERATION[move.move_type]
!= move.fiscal_document_id.fiscal_operation_type
):
raise UserError(_("Fiscal Operation Type mismatch!"))
elif move.company_id != move.fiscal_document_id.company_id:
raise UserError(_("Company mismatch!"))

move_fiscal_lines = set(
move.invoice_line_ids.mapped("fiscal_document_line_id")
)
fiscal_doc_lines = set(move.fiscal_document_id.fiscal_line_ids)
if move_fiscal_lines == fiscal_doc_lines:
raise UserError(_("No new Fiscal Document Line to import!"))

self.import_fiscal_document(move.fiscal_document_id, move_id=move.id)
# def button_import_fiscal_document(self):
# """
# Import move fields and invoice lines from
# the fiscal_document_id record if there is any new line
# to import.
# You can typically set fiscal_document_id to
# some l10n_br_fiscal.document
# record that was imported previously and import its lines into the
# current move.
# """
# for move in self:
# if move.state != "draft":
# raise UserError(_("Cannot import in
# non draft Account Move!"))
# elif (
# move.partner_id
# and move.partner_id != move.fiscal_document_id.partner_id
# ):
# raise UserError(_("Partner mismatch!"))
# elif (
# MOVE_TO_OPERATION[move.move_type]
# != move.fiscal_document_id.fiscal_operation_type
# ):
# raise UserError(_("Fiscal Operation Type mismatch!"))
# elif move.company_id != move.fiscal_document_id.company_id:
# raise UserError(_("Company mismatch!"))

# move_fiscal_lines = set(
# move.invoice_line_ids.mapped("fiscal_document_line_id")
# )
# fiscal_doc_lines = set(move.fiscal_document_id.fiscal_line_ids)
# if move_fiscal_lines == fiscal_doc_lines:
# raise UserError(_("No new Fiscal Document Line to import!"))

# self.import_fiscal_document(
# move.fiscal_document_id, move_id=move.id)

@api.model
def import_fiscal_document(
Expand Down
11 changes: 3 additions & 8 deletions l10n_br_account/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,14 @@ def action_import_confirm(self):
account.move(s) at the end of the attachments sequence.
"""
move_type = "%s_invoice" % (self.fiscal_operation_type,)
move_id = (
self.env["account.move"]
.import_fiscal_document(
fiscal_document,
move_type=move_type,
)
.id
move_id = self.env["account.move"].import_fiscal_document(
self, move_type=move_type
)
return {
"name": _("Imported Invoices"),
"type": "ir.actions.act_window",
"target": "current",
"views": [[False, "tree"], [False, "form"]],
"res_ids": move_id.ids,
"res_ids": [move_id.id],
"res_model": "account.move",
}

0 comments on commit d1a8056

Please sign in to comment.