Skip to content

Commit

Permalink
stock_release_channel: multi-company support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix committed Sep 24, 2024
1 parent ca9d9bc commit 1c06dcd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions stock_release_channel/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ class ResPartner(models.Model):
column1="partner_id",
column2="channel_id",
string="Release Channels",
domain="company_id and [('company_id', '=', company_id)] or []",
)
1 change: 1 addition & 0 deletions stock_release_channel/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _get_release_channel_possible_candidate_domain_channel(self):

def _get_release_channel_possible_candidate_domain_picking(self):
return [
("company_id", "=", self.company_id.id),
"|",
("picking_type_ids", "=", False),
("picking_type_ids", "in", self.picking_type_id.ids),
Expand Down
15 changes: 13 additions & 2 deletions stock_release_channel/models/stock_release_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ class StockReleaseChannel(models.Model):
release_forbidden = fields.Boolean(string="Forbid to release this channel")
sequence = fields.Integer(default=lambda self: self._default_sequence())
color = fields.Integer()
company_id = fields.Many2one(
string="Company",
comodel_name="res.company",
required=True,
default=lambda s: s.env.company.id,
index=True,
)
warehouse_id = fields.Many2one(
"stock.warehouse",
string="Warehouse",
index=True,
help="Warehouse for which this channel is relevant",
check_company=True,
)
picking_type_ids = fields.Many2many(
"stock.picking.type",
Expand All @@ -54,8 +62,9 @@ class StockReleaseChannel(models.Model):
"picking_type_id",
string="Operation Types",
domain="warehouse_id"
" and [('warehouse_id', '=', warehouse_id), ('code', '=', 'outgoing')]"
" or [('code', '=', 'outgoing')]",
" and [('warehouse_id', '=', warehouse_id), ('code', '=', 'outgoing'), "
"('company_id', 'in', (company_id, False))]"
" or [('code', '=', 'outgoing'), ('company_id', 'in', (company_id, False))]",
)
rule_domain = fields.Char(
string="Domain",
Expand Down Expand Up @@ -91,6 +100,7 @@ class StockReleaseChannel(models.Model):
string="Transfers",
comodel_name="stock.picking",
inverse_name="release_channel_id",
check_company=True,
)

# beware not to store any value which can be changed by concurrent
Expand Down Expand Up @@ -219,6 +229,7 @@ class StockReleaseChannel(models.Model):
column2="partner_id",
string="Partners",
context={"active_test": False},
check_company=True,
)
show_last_picking_done = fields.Boolean(
compute="_compute_show_last_picking_done",
Expand Down
1 change: 1 addition & 0 deletions stock_release_channel/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ReleaseChannelCase(common.TransactionCase):
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.company2 = cls.env.ref("stock.res_company_1")
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.default_channel = cls.env.ref(
"stock_release_channel.stock_release_channel_default"
Expand Down
12 changes: 12 additions & 0 deletions stock_release_channel/tests/test_release_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def test_assign_channel_domain_and_code(self):
)
self._test_assign_channels(channel)

def test_assign_channel_invalid_company(self):
# Create a channel for high priority moves but for another company
self._create_channel(
name="Test Domain",
sequence=1,
rule_domain=[("priority", "=", "1")],
company_id=self.company2.id,
)
# This move with high priority is then put in a transfer belonging to
# the default channel (default company)
self._test_assign_channels(self.default_channel)

def test_invalid_code(self):
with self.assertRaises(exceptions.ValidationError):
self._create_channel(
Expand Down
8 changes: 8 additions & 0 deletions stock_release_channel/views/stock_release_channel_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
<h1>
<field name="name" />
</h1>
<group>
<field name="company_id" invisible="1" />
<field
name="company_id"
groups="base.group_multi_company"
options="{'no_create': True}"
/>
</group>
<notebook>
<page
string="Options"
Expand Down

0 comments on commit 1c06dcd

Please sign in to comment.