Skip to content

Commit

Permalink
⚡ company rule for multi-session model
Browse files Browse the repository at this point in the history
  • Loading branch information
KolushovAlexandr committed Nov 11, 2019
1 parent 7014006 commit 0d2c3fd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pos_multi_session/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pos_multi_session/doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
--------
Expand Down
15 changes: 6 additions & 9 deletions pos_multi_session/models/pos_multi_session_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([]))
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pos_multi_session/security/ir_rule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
<odoo>
<record id="pos_multi_session_rule" model="ir.rule">
<field name="name">Multi Session Rule</field>
<field name="model_id" ref="pos_multi_session.model_pos_multi_session"/>
<field name="global" eval="False"/>
<field name="groups" eval="[(6, 0, [ref('base.group_user')])]"/>
<field name="domain_force">[('company_id','child_of',[user.company_id.id])]</field>
</record>
</odoo>

0 comments on commit 0d2c3fd

Please sign in to comment.