diff --git a/sale_order_batch/README.rst b/sale_order_batch/README.rst
index 4eb7562..0a5db41 100644
--- a/sale_order_batch/README.rst
+++ b/sale_order_batch/README.rst
@@ -35,6 +35,7 @@ Changelog
=========
:0.0.1: Initial module.
+:1.0.0: Add Multi Company ability
Bug Tracker
===========
diff --git a/sale_order_batch/__manifest__.py b/sale_order_batch/__manifest__.py
index b88156b..a169d71 100644
--- a/sale_order_batch/__manifest__.py
+++ b/sale_order_batch/__manifest__.py
@@ -13,6 +13,7 @@
"views/sale_order_views.xml",
"views/sale_menus.xml",
"security/ir.model.access.csv",
+ "security/ir_rules.xml",
],
"license": "LGPL-3",
}
diff --git a/sale_order_batch/models/sale_order.py b/sale_order_batch/models/sale_order.py
index 1fdf8bc..aef654c 100644
--- a/sale_order_batch/models/sale_order.py
+++ b/sale_order_batch/models/sale_order.py
@@ -5,13 +5,16 @@ from odoo.exceptions import UserError
class SaleOrder(models.Model):
_inherit = "sale.order"
- batch_id = fields.Many2one("sale.order.batch", copy=False)
+ batch_id = fields.Many2one("sale.order.batch", copy=False, check_company=True)
def action_add_to_batch(self):
"""
TODO: Add Wizard to choose between batches if more than one existis. Picking the first one for now.
"""
- batch = self.env["sale.order.batch"].search([("state", "=", "open")], limit=1)
+ self = self.with_company(self.company_id)
+ batch = self.env["sale.order.batch"].search(
+ [("state", "=", "open"), ("company_id", "=", self.company_id.id)], limit=1
+ )
if not batch:
batch = self.env["sale.order.batch"].create({})
for sale_order in self:
diff --git a/sale_order_batch/models/sale_order_batch.py b/sale_order_batch/models/sale_order_batch.py
index 1bea44b..c374447 100644
--- a/sale_order_batch/models/sale_order_batch.py
+++ b/sale_order_batch/models/sale_order_batch.py
@@ -11,11 +11,7 @@ class SaleOrderBatch(models.Model):
_description = "Sale Order Batch"
_inherit = "mail.thread"
_order = "date_order desc, id desc"
-
- # TODO: add company_id to sale order batch
- # company_id = fields.Many2one(
- # related='order_id.company_id',
- # store=True, index=True, precompute=True)
+ _check_company_auto = True
name = fields.Char(
string="Order Batch Reference",
@@ -25,6 +21,9 @@ class SaleOrderBatch(models.Model):
index="trigram",
default=lambda self: _("New"),
)
+ company_id = fields.Many2one(
+ comodel_name="res.company", required=True, index=True, default=lambda self: self.env.company
+ )
state = fields.Selection(
selection=[("open", "Open"), ("closed", "Closed")],
string="Status",
diff --git a/sale_order_batch/readme/HISTORY.rst b/sale_order_batch/readme/HISTORY.rst
index e986fe7..7322126 100644
--- a/sale_order_batch/readme/HISTORY.rst
+++ b/sale_order_batch/readme/HISTORY.rst
@@ -1 +1,2 @@
-:0.0.1: Initial module.
\ No newline at end of file
+:0.0.1: Initial module.
+:1.0.0: Add Multi Company ability
\ No newline at end of file
diff --git a/sale_order_batch/security/ir_rules.xml b/sale_order_batch/security/ir_rules.xml
new file mode 100644
index 0000000..7abb22e
--- /dev/null
+++ b/sale_order_batch/security/ir_rules.xml
@@ -0,0 +1,11 @@
+
+