Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions purchase_sale_inter_company/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ class ResCompany(models.Model):
string="Block manual validation of picking in the destination company",
)
notify_user_id = fields.Many2one("res.users", "User to Notify")
notification_side = fields.Selection(
[("so", "Sale Order Source Company"), ("po", "Purchase Destination Company")],
default="so",
help="Select which Company side to notify",
)
3 changes: 3 additions & 0 deletions purchase_sale_inter_company/models/res_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ class InterCompanyRulesConfig(models.TransientModel):
help="User to notify incase of sync picking failure.",
readonly=False,
)
notification_side = fields.Selection(
related="company_id.notification_side", string="Notify", readonly=False
)
44 changes: 22 additions & 22 deletions purchase_sale_inter_company/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,14 @@ def _action_done_intercompany_actions(self, purchase):
).mapped("move_line_ids")
)
if len(move_lines) != len(po_move_lines):
note = _(
"Mismatch between move lines with the "
"corresponding PO %s for assigning "
"quantities and lots from %s for product %s"
) % (purchase.name, pick.name, move.product_id.name)
self.activity_schedule(
"mail.mail_activity_data_warning",
fields.Date.today(),
note=note,
# Try to notify someone relevant
user_id=(
pick.sale_id.user_id.id
or pick.sale_id.team_id.user_id.id
or SUPERUSER_ID,
),
self._notify_picking_problem(
purchase,
additional_note=_(
"Mismatch between move lines with the "
"corresponding PO %s for assigning "
"quantities and lots from %s for product %s"
)
% (purchase.name, pick.name, move.product_id.name),
)
# check and assign lots here
for ml, po_ml in zip(move_lines, po_move_lines):
Expand Down Expand Up @@ -103,25 +96,32 @@ def _action_done_intercompany_actions(self, purchase):
else:
self._notify_picking_problem(purchase)

def _notify_picking_problem(self, purchase):
def _notify_picking_problem(self, purchase, additional_note=False):
self.ensure_one()
note = _(
"Failure to confirm picking for PO %s. "
"Original picking %s still confirmed, please check "
"the other side manually."
) % (purchase.name, self.name)
self.activity_schedule(
if additional_note:
note += _(" Additional info: ") + additional_note
user_id = self.sudo()._get_user_to_notify(purchase)
self.sudo().activity_schedule(
"mail.mail_activity_data_warning",
fields.Date.today(),
note=note,
# Try to notify someone relevant
user_id=(
user_id=user_id or SUPERUSER_ID,
)

def _get_user_to_notify(self, purchase):
"""Notify user based on res.config.settings"""
if self.company_id.notification_side == "so":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rare case where someone wants different notification sides for different dropshipping companies, maybe this should be purchase.company_id.notification_side instead. So that people can configure it per target company.

return (
self.company_id.notify_user_id.id
or self.sale_id.user_id.id
or self.sale_id.team_id.user_id.id
or SUPERUSER_ID,
),
)
)
return purchase.user_id.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rather be purchase.company_id.notify_user.id or purchase.user_id.id, I think, so that it can be configured on the target company side.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So in res.config.settings, I have made notify_user_id a required field, only when notification_side is configured for source company sale.order. So first I should remove this restriction, and then make this change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes.


def button_validate(self):
res = super().button_validate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,43 @@ def test_notify_picking_problem(self):
warning_activity.user_id, so_picking_id.company_id.notify_user_id
)

def test_notify_picking_problem_dest_company(self):
self.company_a.sync_picking = True
self.company_b.sync_picking = True
self.company_a.sync_picking_failure_action = "notify"
self.company_b.sync_picking_failure_action = "notify"
self.company_a.notification_side = "po"
self.company_b.notification_side = "po"
purchase = self._create_purchase_order(
self.partner_company_b, self.consumable_product
)
purchase_2 = self._create_purchase_order(
self.partner_company_b, self.consumable_product
)
purchase.order_line += purchase.order_line.copy({"product_qty": 2})
sale = self._approve_po(purchase)
sale.action_confirm()

# validate the SO picking
so_picking_id = sale.picking_ids
# Set as purchase_2 user user_company_a
purchase_2.user_id = self.user_company_a
# Link to a new purchase order so it can trigger
# `PO does not exist or has no receipts` in _sync_receipt_with_delivery
sale.auto_purchase_order_id = purchase_2

# Set quantities done on the picking and validate
for move in so_picking_id.move_lines:
move.quantity_done = move.product_uom_qty
so_picking_id.button_validate()

activity_warning = self.env.ref("mail.mail_activity_data_warning")
warning_activity = so_picking_id.activity_ids.filtered(
lambda a: a.activity_type_id == activity_warning
)
# Test the user assigned to the activity
self.assertEqual(warning_activity.user_id, self.user_company_a)

def test_raise_picking_problem(self):
self.company_a.sync_picking = True
self.company_b.sync_picking = True
Expand Down
14 changes: 13 additions & 1 deletion purchase_sale_inter_company/views/res_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,26 @@
for="sync_picking_failure_action"
/>
<br />
<label
for="notification_side"
class="o_light_label"
attrs="{'invisible': [('sync_picking_failure_action', '!=', 'notify')]}"
/>
<field
name="notification_side"
widget="radio"
attrs="{'invisible': [('sync_picking_failure_action', '!=', 'notify')], 'required': [('sync_picking_failure_action', '=', 'notify')]}"
class="oe_inline"
/>
<br />
<label
for="notify_user_id"
class="o_light_label"
attrs="{'invisible': [('sync_picking_failure_action', '!=', 'notify')]}"
/>
<field
name="notify_user_id"
attrs="{'invisible': [('sync_picking_failure_action', '!=', 'notify')], 'required': [('sync_picking_failure_action', '=', 'notify')]}"
attrs="{'invisible': [('sync_picking_failure_action', '!=', 'notify')], 'required': [('sync_picking_failure_action', '=', 'notify'), ('notification_side', '=', 'so')]}"
class="oe_inline"
/>
<br />
Expand Down