Skip to content

Commit

Permalink
Merge PR #1078 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dhongu
  • Loading branch information
OCA-git-bot committed Sep 29, 2024
2 parents ed949e5 + cc92b7d commit 5d0b98a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
11 changes: 11 additions & 0 deletions l10n_ro_message_spv/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ class AccountMove(models.Model):
string="Romania - E-invoice messages",
help="E-invoice messages related to this invoice.",
)

def unlink(self):
domain = [("invoice_id", "in", self.ids)]
message_spv_ids = self.env["l10n.ro.message.spv"].search(domain)
attachments = self.env["ir.attachment"]
attachments += message_spv_ids.mapped("attachment_id")
attachments += message_spv_ids.mapped("attachment_xml_id")
attachments += message_spv_ids.mapped("attachment_anaf_pdf_id")
attachments += message_spv_ids.mapped("attachment_embedded_pdf_id")
attachments.sudo().write({"res_id": False, "res_model": False})
return super().unlink()
24 changes: 22 additions & 2 deletions l10n_ro_message_spv/models/message_spv.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def check_anaf_message_xml(self, zip_content):
return info_msg

def get_invoice_from_move(self):
self.get_partner()
messages_without_invoice = self.filtered(lambda m: not m.invoice_id)
message_ids = messages_without_invoice.mapped("name")
request_ids = messages_without_invoice.mapped("request_id")
Expand Down Expand Up @@ -310,6 +311,7 @@ def get_invoice_from_move(self):
self.get_data_from_invoice()

def get_data_from_invoice(self):
self.get_partner()
for message in self:
if not message.invoice_id:
continue
Expand All @@ -324,7 +326,8 @@ def get_data_from_invoice(self):

message.write(
{
"partner_id": message.invoice_id.commercial_partner_id.id,
"partner_id": message.invoice_id.commercial_partner_id.id
or message.partner_id.id,
"invoice_amount": invoice_amount,
"state": state,
}
Expand All @@ -336,11 +339,12 @@ def get_data_from_invoice(self):
attachments += message.attachment_xml_id
attachments += message.attachment_anaf_pdf_id
attachments += message.attachment_embedded_pdf_id
attachments.write(
attachments.sudo().write(
{"res_id": message.invoice_id.id, "res_model": "account.move"}
)

def create_invoice(self):
self.get_partner()
for message in self.filtered(lambda m: not m.invoice_id):
if not message.message_type == "in_invoice":
continue
Expand Down Expand Up @@ -473,3 +477,19 @@ def _action_download(self, attachment_field_id):
"url": f"/web/content/{attachment_field_id}?download=true",
"target": "self",
}

def get_partner(self):

for message in self.filtered(lambda m: not m.partner_id):
if message.cif:
domain = [("vat", "like", message.cif), ("is_company", "=", True)]
partner = self.env["res.partner"].search(domain, limit=1)
if not partner:
partner = self.env["res.partner"].create(
{
"name": message.cif,
"vat": message.cif,
"is_company": True,
}
)
message.write({"partner_id": partner.id})

0 comments on commit 5d0b98a

Please sign in to comment.