From 432dd3ebb6152c1df726c363144db7534874c77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Fri, 27 Sep 2024 17:13:39 +0200 Subject: [PATCH] [imp] add multi company ability --- sale_order_batch/README.rst | 1 + sale_order_batch/__manifest__.py | 1 + sale_order_batch/models/sale_order.py | 7 +++++-- sale_order_batch/models/sale_order_batch.py | 9 ++++----- sale_order_batch/readme/HISTORY.rst | 3 ++- sale_order_batch/security/ir_rules.xml | 11 +++++++++++ sale_order_batch/static/description/index.html | 2 ++ 7 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 sale_order_batch/security/ir_rules.xml 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 @@ + + + + + + Sales Order Batch multi-company + + [('company_id', 'in', company_ids)] + + + diff --git a/sale_order_batch/static/description/index.html b/sale_order_batch/static/description/index.html index 79ce309..6404dbf 100644 --- a/sale_order_batch/static/description/index.html +++ b/sale_order_batch/static/description/index.html @@ -394,6 +394,8 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation 0.0.1:Initial module. +1.0.0:Add Multi Company ability +