From 0d2c3fdf80fae9892cc143e0fea116ad6222d070 Mon Sep 17 00:00:00 2001 From: KolushovAlexandr Date: Mon, 11 Nov 2019 14:43:15 +0500 Subject: [PATCH] :zap: company rule for multi-session model --- pos_multi_session/__manifest__.py | 3 ++- pos_multi_session/doc/changelog.rst | 1 + .../models/pos_multi_session_models.py | 15 ++++++--------- pos_multi_session/security/ir_rule.xml | 12 ++++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 pos_multi_session/security/ir_rule.xml diff --git a/pos_multi_session/__manifest__.py b/pos_multi_session/__manifest__.py index 8727583fa6..03d8a617ac 100644 --- a/pos_multi_session/__manifest__.py +++ b/pos_multi_session/__manifest__.py @@ -28,7 +28,8 @@ "data/pos_multi_session_data.xml", "security/ir.model.access.csv", "views/pos_multi_session_views.xml", - "multi_session_view.xml" + "multi_session_view.xml", + "security/ir_rule.xml", ], "qweb": [ "static/src/xml/pos_multi_session.xml", diff --git a/pos_multi_session/doc/changelog.rst b/pos_multi_session/doc/changelog.rst index b451a4a0f9..a7a8427eaf 100644 --- a/pos_multi_session/doc/changelog.rst +++ b/pos_multi_session/doc/changelog.rst @@ -3,6 +3,7 @@ - **Fix:** Access error for poses created for different companies - **Fix:** Error during installation in multi-company mode +- **Improvement:** Company rule for multi-session model `4.2.10` -------- diff --git a/pos_multi_session/models/pos_multi_session_models.py b/pos_multi_session/models/pos_multi_session_models.py index 3c587c1330..d709379b82 100644 --- a/pos_multi_session/models/pos_multi_session_models.py +++ b/pos_multi_session/models/pos_multi_session_models.py @@ -27,7 +27,7 @@ class PosConfig(models.Model): autostart_longpolling = fields.Boolean(default=False) fiscal_position_ids = fields.Many2many(related='multi_session_id.fiscal_position_ids') company_id = fields.Many2one(related='multi_session_id.company_id', store=True, default=lambda self: self.env.user.company_id) - stock_location_id = fields.Many2one(related='multi_session_id.stock_location_id', store=True) + # stock_location_id = fields.Many2one(related='multi_session_id.stock_location_id', store=True) def _search_current_session_state(self, operator, value): ids = map(lambda x: x.id, self.env["pos.config"].search([])) @@ -59,30 +59,27 @@ def _get_default_location(self): "It's used to prevent synchronization of old orders") fiscal_position_ids = fields.Many2many('account.fiscal.position', string='Fiscal Positions', ondelete="restrict") company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id) - stock_location_id = fields.Many2one( - 'stock.location', string='Stock Location', - domain=[('usage', '=', 'internal')], required=True, default=_get_default_location) @api.model def action_set_default_multi_session(self): """ - during installation of the module set default multi-sessions (separate default multi-session for every company) - for all POSes for which multi_session_id is not specified + during installation of the module set default multi-sessions + (separate default multi-session for each company) + for all POSes with not set multi_session_id """ companies = self.env['res.company'].search([]) for company in companies: configs = self.env['pos.config'].search([('multi_session_id', '=', False), ('company_id', '=', company.id)]) - # If exist POSes with the company then we need to create default multi-session + # If there are POSes with the company then we need to create default multi-session if configs: # Create default multi-session for current company - stock_location = self.env['stock.warehouse'].search([('company_id', '=', company.id)], limit=1).lot_stock_id multi_session = self.create({ 'name': 'Default Multi Session (%s)' % company.name, 'multi_session_active': False, 'company_id': company.id, - 'stock_location_id': stock_location.id }) + # odoo.exceptions.ValidationError: ('Error while validating constraint\n\nExpected singleton: pos.config(1, 2, 3)', None) for c in configs: c.write({ 'multi_session_id': multi_session.id diff --git a/pos_multi_session/security/ir_rule.xml b/pos_multi_session/security/ir_rule.xml new file mode 100644 index 0000000000..b015d13664 --- /dev/null +++ b/pos_multi_session/security/ir_rule.xml @@ -0,0 +1,12 @@ + + + + + Multi Session Rule + + + + [('company_id','child_of',[user.company_id.id])] + +