Skip to content

Commit

Permalink
s_a_bill_auto_complete: add info in chatter
Browse files Browse the repository at this point in the history
When a vendor bill is auto completed from a shipment advice.
Log the information with a ling to the shipment.
  • Loading branch information
TDu committed Oct 11, 2024
1 parent 6c247ac commit 1be721d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions shipment_advice_bill_auto_complete/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,45 @@ def _get_purchase_quantity_from_stock_move_line(self, po_line, move_lines):
if move_lines.product_id == po_line.product_id:
quantity_done = sum(move_lines.mapped("qty_done"))
return quantity_done

@api.model_create_multi
def create(self, vals_list):
moves = super().create(vals_list)
for move in moves:
if move.move_type not in ("in_invoice", "out_refund"):
continue

Check warning on line 109 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L109

Added line #L109 was not covered by tests
shipment = move.line_ids.mapped("shipment_advice_id")
if not shipment:
continue
refs = [
"<a href=# data-oe-model=shipment.advice data-oe-id=%s>%s</a>"
% tuple(name_get)
for name_get in shipment.name_get()
]
message = _("This vendor bill has been created from: %s") % ",".join(refs)
move.message_post(body=message)
return moves

def write(self, vals):
old_shipment = {
move.id: move.mapped("line_ids.shipment_advice_id") for move in self
}
res = super().write(vals)

Check warning on line 126 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L126

Added line #L126 was not covered by tests
for move in self:
if move.move_type not in ("in_invoice", "out_refund"):
continue
new_shipment = move.mapped("line_ids.shipment_advice_id")

Check warning on line 130 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L129-L130

Added lines #L129 - L130 were not covered by tests
if not new_shipment:
continue
diff_shipments = new_shipment - old_shipment[move.id]

Check warning on line 133 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L132-L133

Added lines #L132 - L133 were not covered by tests
if diff_shipments:
refs = [
"<a href=# data-oe-model=shipment.advice data-oe-id=%s>%s</a>"
% tuple(name_get)
for name_get in diff_shipments.name_get()
]
message = _("This vendor bill has been modified from: %s") % ",".join(

Check warning on line 140 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L140

Added line #L140 was not covered by tests
refs
)
move.message_post(body=message)
return res

Check warning on line 144 in shipment_advice_bill_auto_complete/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice_bill_auto_complete/models/account_move.py#L143-L144

Added lines #L143 - L144 were not covered by tests

0 comments on commit 1be721d

Please sign in to comment.