Skip to content

Commit 0d2c3fd

Browse files
⚡ company rule for multi-session model
1 parent 7014006 commit 0d2c3fd

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

pos_multi_session/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"data/pos_multi_session_data.xml",
2929
"security/ir.model.access.csv",
3030
"views/pos_multi_session_views.xml",
31-
"multi_session_view.xml"
31+
"multi_session_view.xml",
32+
"security/ir_rule.xml",
3233
],
3334
"qweb": [
3435
"static/src/xml/pos_multi_session.xml",

pos_multi_session/doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
- **Fix:** Access error for poses created for different companies
55
- **Fix:** Error during installation in multi-company mode
6+
- **Improvement:** Company rule for multi-session model
67

78
`4.2.10`
89
--------

pos_multi_session/models/pos_multi_session_models.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PosConfig(models.Model):
2727
autostart_longpolling = fields.Boolean(default=False)
2828
fiscal_position_ids = fields.Many2many(related='multi_session_id.fiscal_position_ids')
2929
company_id = fields.Many2one(related='multi_session_id.company_id', store=True, default=lambda self: self.env.user.company_id)
30-
stock_location_id = fields.Many2one(related='multi_session_id.stock_location_id', store=True)
30+
# stock_location_id = fields.Many2one(related='multi_session_id.stock_location_id', store=True)
3131

3232
def _search_current_session_state(self, operator, value):
3333
ids = map(lambda x: x.id, self.env["pos.config"].search([]))
@@ -59,30 +59,27 @@ def _get_default_location(self):
5959
"It's used to prevent synchronization of old orders")
6060
fiscal_position_ids = fields.Many2many('account.fiscal.position', string='Fiscal Positions', ondelete="restrict")
6161
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
62-
stock_location_id = fields.Many2one(
63-
'stock.location', string='Stock Location',
64-
domain=[('usage', '=', 'internal')], required=True, default=_get_default_location)
6562

6663
@api.model
6764
def action_set_default_multi_session(self):
6865
"""
69-
during installation of the module set default multi-sessions (separate default multi-session for every company)
70-
for all POSes for which multi_session_id is not specified
66+
during installation of the module set default multi-sessions
67+
(separate default multi-session for each company)
68+
for all POSes with not set multi_session_id
7169
"""
7270
companies = self.env['res.company'].search([])
7371
for company in companies:
7472
configs = self.env['pos.config'].search([('multi_session_id', '=', False), ('company_id', '=', company.id)])
7573

76-
# If exist POSes with the company then we need to create default multi-session
74+
# If there are POSes with the company then we need to create default multi-session
7775
if configs:
7876
# Create default multi-session for current company
79-
stock_location = self.env['stock.warehouse'].search([('company_id', '=', company.id)], limit=1).lot_stock_id
8077
multi_session = self.create({
8178
'name': 'Default Multi Session (%s)' % company.name,
8279
'multi_session_active': False,
8380
'company_id': company.id,
84-
'stock_location_id': stock_location.id
8581
})
82+
# odoo.exceptions.ValidationError: ('Error while validating constraint\n\nExpected singleton: pos.config(1, 2, 3)', None)
8683
for c in configs:
8784
c.write({
8885
'multi_session_id': multi_session.id
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2019 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
3+
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
4+
<odoo>
5+
<record id="pos_multi_session_rule" model="ir.rule">
6+
<field name="name">Multi Session Rule</field>
7+
<field name="model_id" ref="pos_multi_session.model_pos_multi_session"/>
8+
<field name="global" eval="False"/>
9+
<field name="groups" eval="[(6, 0, [ref('base.group_user')])]"/>
10+
<field name="domain_force">[('company_id','child_of',[user.company_id.id])]</field>
11+
</record>
12+
</odoo>

0 commit comments

Comments
 (0)