Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! [IMP] purchase_sale_inter_company: Create one SO from PO, if e…
Browse files Browse the repository at this point in the history
…xists -> modify existing
yankinmax committed Nov 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 594a403 commit 6cf782d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions purchase_sale_inter_company/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -43,18 +43,25 @@ def button_approve(self, force=False):
dest_company = (
po_partner.ref_company_ids or po_partner.parent_id.ref_company_ids
)
if len(dest_company) > 1:
raise UserError(

Check warning on line 47 in purchase_sale_inter_company/models/purchase_order.py

Codecov / codecov/patch

purchase_sale_inter_company/models/purchase_order.py#L47

Added line #L47 was not covered by tests
_("You can generate sale order only for one vendor company at once")
)
intercompany_user = dest_company.intercompany_sale_user_id
if not intercompany_user:
intercompany_user = self.env.user

Check warning on line 52 in purchase_sale_inter_company/models/purchase_order.py

Codecov / codecov/patch

purchase_sale_inter_company/models/purchase_order.py#L52

Added line #L52 was not covered by tests
if dest_company and dest_company.so_from_po:
# one sale order is expected to be created when confirm purchase order
# so we check for existing sale order with auto_purchase_order_id set
# and confirm that sale order if found (it's possible it can be draft)
# we don't need extra sale orders if purchase order was confirmed again
auto_sale_order_id = (
self.env["sale.order"]
.sudo()
.search([("auto_purchase_order_id", "=", purchase_order.id)])
)
# standard OCA flow raises an error if we try to confirm purchase order
# with already generated auto sale order, comment it for now
# if len(auto_sale_order_id) > 1:
# raise UserError(
# _(
@@ -63,10 +70,11 @@ def button_approve(self, force=False):
# )
# % ",".join([order.display_name for order in auto_sale_order_id])
# )
if auto_sale_order_id and (
auto_sale_order_id.state not in ("sale", "done")
):
auto_sale_order_id.with_user(
if auto_sale_order_id:
not_confirmed_orders = auto_sale_order_id.filtered(
lambda order: order.state not in ("sale", "done")
)
not_confirmed_orders.with_user(

Check warning on line 77 in purchase_sale_inter_company/models/purchase_order.py

Codecov / codecov/patch

purchase_sale_inter_company/models/purchase_order.py#L77

Added line #L77 was not covered by tests
intercompany_user.id
).sudo().action_confirm()
else:

0 comments on commit 6cf782d

Please sign in to comment.