Skip to content

Commit 7014006

Browse files
digaKolushovAlexandr
authored andcommitted
🚑 Error during installation in multi-company mode
1 parent a177cb5 commit 7014006

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- Copyright 2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
2+
<!-- Copyright 2018-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
33
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
44

55
<odoo noupdate="1">
66

7-
<record id="default_multi_session" model="pos.multi_session">
8-
<field name="name">Default Multi Session</field>
9-
<field name="multi_session_active">False</field>
10-
</record>
11-
12-
<record id="point_of_sale.pos_config_main" model="pos.config">
13-
<field name="multi_session_id" ref="default_multi_session"/>
14-
</record>
15-
16-
<!-- Default multi session for exist POSes -->
17-
<function model="pos.multi_session" name="action_set_default_multi_session" eval="[[ref('default_multi_session')]]"/>
7+
<!-- Create default multi sessions for each company -->
8+
<function model="pos.multi_session" name="action_set_default_multi_session" />
189

1910
</odoo>

pos_multi_session/demo/demo.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Copyright 2016 Ilyas Rakhimkulov
3-
Copyright 2016,2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
3+
Copyright 2016,2018-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
44
Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
55
Copyright 2017 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
66
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
@@ -26,7 +26,6 @@
2626

2727
<record id="partner_demo2" model="res.partner">
2828
<field name="name">Demo User2</field>
29-
<field name="company_id" ref="base.main_company"/>
3029
<field name="customer" eval="False"/>
3130
<field name="email">demo2@yourcompany.example.com</field>
3231
<field name="street">Avenue des Dessus-de-Lives2, 2</field>
@@ -38,7 +37,6 @@
3837
<field name="login">demo2</field>
3938
<field name="password">demo2</field>
4039
<field name="signature">--Mr Demo2</field>
41-
<field name="company_id" ref="base.main_company"/>
4240
<field name="groups_id" eval="[(6,0,[ref('base.group_user'), ref('base.group_partner_manager'), ref('point_of_sale.group_pos_user')])]"/>
4341
<field name="image" type="base64" file="base/static/img/user_demo-image.jpg"/>
4442
<field name="pos_security_pin">0410100000013</field>

pos_multi_session/doc/changelog.rst

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

44
- **Fix:** Access error for poses created for different companies
5+
- **Fix:** Error during installation in multi-company mode
56

67
`4.2.10`
78
--------

pos_multi_session/models/pos_multi_session_models.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2015-2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
22
# Copyright 2016 Ilyas Rakhimkulov
33
# Copyright 2017 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
4-
# Copyright 2016-2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
4+
# Copyright 2016-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
55
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
66

77
import logging
@@ -18,16 +18,16 @@ class PosConfig(models.Model):
1818
multi_session_id = fields.Many2one('pos.multi_session', 'Multi-session',
1919
help='Set the same value for POSes where orders should be synced.'
2020
'Uncheck the box "Active" if the POS should not use syncing.'
21-
'Before updating you need to close active session',
22-
default=lambda self: self.env.ref('pos_multi_session.default_multi_session', raise_if_not_found=False))
21+
'Before updating you need to close active session')
2322
multi_session_accept_incoming_orders = fields.Boolean('Accept incoming orders', default=True)
2423
multi_session_replace_empty_order = fields.Boolean('Replace empty order', default=True, help='Empty order is deleted whenever new order is come from another POS')
2524
multi_session_deactivate_empty_order = fields.Boolean('Deactivate empty order', default=False, help='POS is switched to new foreign Order, if current order is empty')
2625
current_session_state = fields.Char(search='_search_current_session_state')
2726
sync_server = fields.Char(related='multi_session_id.sync_server')
2827
autostart_longpolling = fields.Boolean(default=False)
2928
fiscal_position_ids = fields.Many2many(related='multi_session_id.fiscal_position_ids')
30-
company_id = fields.Many2one(related='multi_session_id.company_id')
29+
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)
3131

3232
def _search_current_session_state(self, operator, value):
3333
ids = map(lambda x: x.id, self.env["pos.config"].search([]))
@@ -45,6 +45,9 @@ def _search_current_session_state(self, operator, value):
4545
class PosMultiSession(models.Model):
4646
_name = 'pos.multi_session'
4747

48+
def _get_default_location(self):
49+
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id
50+
4851
name = fields.Char('Name')
4952
multi_session_active = fields.Boolean(string="Active", help="Select the checkbox to enable synchronization for POSes", default=True)
5053
pos_ids = fields.One2many('pos.config', 'multi_session_id', string='POSes in Multi-session')
@@ -56,18 +59,34 @@ class PosMultiSession(models.Model):
5659
"It's used to prevent synchronization of old orders")
5760
fiscal_position_ids = fields.Many2many('account.fiscal.position', string='Fiscal Positions', ondelete="restrict")
5861
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)
5965

60-
@api.multi
66+
@api.model
6167
def action_set_default_multi_session(self):
6268
"""
63-
during installation of the module set default multi-session
69+
during installation of the module set default multi-sessions (separate default multi-session for every company)
6470
for all POSes for which multi_session_id is not specified
6571
"""
66-
self.ensure_one()
67-
configs = self.env['pos.config'].search([('multi_session_id', '=', False)])
68-
configs.write({
69-
'multi_session_id': self.id
70-
})
72+
companies = self.env['res.company'].search([])
73+
for company in companies:
74+
configs = self.env['pos.config'].search([('multi_session_id', '=', False), ('company_id', '=', company.id)])
75+
76+
# If exist POSes with the company then we need to create default multi-session
77+
if configs:
78+
# Create default multi-session for current company
79+
stock_location = self.env['stock.warehouse'].search([('company_id', '=', company.id)], limit=1).lot_stock_id
80+
multi_session = self.create({
81+
'name': 'Default Multi Session (%s)' % company.name,
82+
'multi_session_active': False,
83+
'company_id': company.id,
84+
'stock_location_id': stock_location.id
85+
})
86+
for c in configs:
87+
c.write({
88+
'multi_session_id': multi_session.id
89+
})
7190

7291
@api.multi
7392
def name_get(self):

pos_multi_session/views/pos_multi_session_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<label for="multi_session_id"/>
4646
<div class="content-group">
4747
<div class="mt16 row">
48-
<field name="multi_session_id" class="col-xs-3 col-md-3" attrs="{'readonly':[('current_session_state', '=', 'opened')]}"></field>
48+
<field name="multi_session_id" class="col-xs-3 col-md-3" attrs="{'readonly':[('current_session_state', '=', 'opened')]}" required="True"></field>
4949
</div>
5050
</div>
5151
</div>

0 commit comments

Comments
 (0)