Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Jan 20, 2025
1 parent d701bc5 commit c1132cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,53 @@
class AccountMoveSend(models.TransientModel):
_inherit = "account.move.send"

can_attach_attachment = fields.Boolean()
object_attachment_ids = fields.Many2many(
comodel_name="ir.attachment",
relation="account_move_send_ir_attachments_object_rel",
column1="wizard_id",
column2="attachment_id",
string="Object Attachments",
)
display_object_attachment_ids = fields.One2many(
comodel_name="ir.attachment",
compute="_compute_display_object_attachment_ids",
)

@api.depends("move_ids")
def _compute_display_object_attachment_ids(self):
for wizard in self:
if self.move_ids:
attachments = self.env["ir.attachment"].search(

Check warning on line 27 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L27

Added line #L27 was not covered by tests
[
("res_model", "=", "account.move"),
("res_id", "in", self.move_ids.ids),
]
)
wizard.display_object_attachment_ids = attachments

Check warning on line 33 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L33

Added line #L33 was not covered by tests
else:
wizard.display_object_attachment_ids = False

Check warning on line 35 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L35

Added line #L35 was not covered by tests

# def _prepare_mail_values(self, res_ids):
# res = super()._prepare_mail_values(res_ids)
# if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
# res[res_ids[0]].setdefault("attachment_ids", []).extend(
# self.object_attachment_ids.ids
# )
# return res

@api.model
def _get_invoice_extra_attachments(self, move):
res = super()._get_invoice_extra_attachments(move)
res |= self.object_attachment_ids
return res

@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
if (
res.get("res_id")
and res.get("model")
and res.get("composition_mode", "") != "mass_mail"
res.get("move_ids")
and res.get("mode", "") != "invoice_multi"
and not res.get("can_attach_attachment")
):
res["can_attach_attachment"] = True # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
<field name="model">account.move.send</field>
<field name="inherit_id" ref="account.account_move_send_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='attachment_ids']" position="after">
<field name="model" invisible="1" />
<field name="res_id" invisible="1" />
<xpath expr="//field[@name='mail_attachments_widget']" position="after">
<field name="can_attach_attachment" invisible="1" />
<field
name="object_attachment_ids"
widget="many2many_checkboxes"
domain="[('res_model', '=', model), ('res_id', '=', res_id)]"
domain="[('res_model', '=', 'account.move'), ('res_id', 'in', move_ids)]"
invisible="can_attach_attachment==False"
/>
</xpath>
Expand Down

0 comments on commit c1132cd

Please sign in to comment.