Skip to content

Commit

Permalink
🚑 Error during installation in multi-company mode
Browse files Browse the repository at this point in the history
  • Loading branch information
diga authored and KolushovAlexandr committed Nov 1, 2019
1 parent a177cb5 commit 7014006
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
15 changes: 3 additions & 12 deletions pos_multi_session/data/pos_multi_session_data.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
<!-- Copyright 2018-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->

<odoo noupdate="1">

<record id="default_multi_session" model="pos.multi_session">
<field name="name">Default Multi Session</field>
<field name="multi_session_active">False</field>
</record>

<record id="point_of_sale.pos_config_main" model="pos.config">
<field name="multi_session_id" ref="default_multi_session"/>
</record>

<!-- Default multi session for exist POSes -->
<function model="pos.multi_session" name="action_set_default_multi_session" eval="[[ref('default_multi_session')]]"/>
<!-- Create default multi sessions for each company -->
<function model="pos.multi_session" name="action_set_default_multi_session" />

</odoo>
4 changes: 1 addition & 3 deletions pos_multi_session/demo/demo.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Ilyas Rakhimkulov
Copyright 2016,2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
Copyright 2016,2018-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2017 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
Expand All @@ -26,7 +26,6 @@

<record id="partner_demo2" model="res.partner">
<field name="name">Demo User2</field>
<field name="company_id" ref="base.main_company"/>
<field name="customer" eval="False"/>
<field name="email">demo2@yourcompany.example.com</field>
<field name="street">Avenue des Dessus-de-Lives2, 2</field>
Expand All @@ -38,7 +37,6 @@
<field name="login">demo2</field>
<field name="password">demo2</field>
<field name="signature">--Mr Demo2</field>
<field name="company_id" ref="base.main_company"/>
<field name="groups_id" eval="[(6,0,[ref('base.group_user'), ref('base.group_partner_manager'), ref('point_of_sale.group_pos_user')])]"/>
<field name="image" type="base64" file="base/static/img/user_demo-image.jpg"/>
<field name="pos_security_pin">0410100000013</field>
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 @@ -2,6 +2,7 @@
--------

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

`4.2.10`
--------
Expand Down
41 changes: 30 additions & 11 deletions pos_multi_session/models/pos_multi_session_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2015-2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2016 Ilyas Rakhimkulov
# Copyright 2017 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# Copyright 2016-2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
# Copyright 2016-2019 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

import logging
Expand All @@ -18,16 +18,16 @@ class PosConfig(models.Model):
multi_session_id = fields.Many2one('pos.multi_session', 'Multi-session',
help='Set the same value for POSes where orders should be synced.'
'Uncheck the box "Active" if the POS should not use syncing.'
'Before updating you need to close active session',
default=lambda self: self.env.ref('pos_multi_session.default_multi_session', raise_if_not_found=False))
'Before updating you need to close active session')
multi_session_accept_incoming_orders = fields.Boolean('Accept incoming orders', default=True)
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')
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')
current_session_state = fields.Char(search='_search_current_session_state')
sync_server = fields.Char(related='multi_session_id.sync_server')
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')
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)

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

def _get_default_location(self):
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id

name = fields.Char('Name')
multi_session_active = fields.Boolean(string="Active", help="Select the checkbox to enable synchronization for POSes", default=True)
pos_ids = fields.One2many('pos.config', 'multi_session_id', string='POSes in Multi-session')
Expand All @@ -56,18 +59,34 @@ class PosMultiSession(models.Model):
"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.multi
@api.model
def action_set_default_multi_session(self):
"""
during installation of the module set default multi-session
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
"""
self.ensure_one()
configs = self.env['pos.config'].search([('multi_session_id', '=', False)])
configs.write({
'multi_session_id': self.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 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
})
for c in configs:
c.write({
'multi_session_id': multi_session.id
})

@api.multi
def name_get(self):
Expand Down
2 changes: 1 addition & 1 deletion pos_multi_session/views/pos_multi_session_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<label for="multi_session_id"/>
<div class="content-group">
<div class="mt16 row">
<field name="multi_session_id" class="col-xs-3 col-md-3" attrs="{'readonly':[('current_session_state', '=', 'opened')]}"></field>
<field name="multi_session_id" class="col-xs-3 col-md-3" attrs="{'readonly':[('current_session_state', '=', 'opened')]}" required="True"></field>
</div>
</div>
</div>
Expand Down

0 comments on commit 7014006

Please sign in to comment.