-
-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚑 access error for poses created for different companies #1147
base: 11.0
Are you sure you want to change the base?
Changes from 5 commits
a177cb5
7014006
0d2c3fd
9246a57
4354670
6f6e11f
fd72272
2744984
b432eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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). --> | ||
|
@@ -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">[email protected]</field> | ||
<field name="street">Avenue des Dessus-de-Lives2, 2</field> | ||
|
@@ -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> | ||
|
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 2017,2019 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr> | ||
# 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 | ||
|
@@ -18,16 +18,14 @@ 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') | ||
|
||
def _search_current_session_state(self, operator, value): | ||
ids = map(lambda x: x.id, self.env["pos.config"].search([])) | ||
|
@@ -41,10 +39,28 @@ def _search_current_session_state(self, operator, value): | |
else: | ||
return [('id', 'in', [])] | ||
|
||
@api.multi | ||
def _write(self, vals): | ||
# made to prevent 'expected singleton' errors in *pos.config* constraints | ||
result = False | ||
if 'multi_session_id' in vals: | ||
multi_session_id = vals.get('multi_session_id') | ||
if multi_session_id: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я правильно понимаю, что multi_session_id может быть задан в словаре, но иметь значение вида 0, False или None? Меня тут смутило то, что мы сначала проверяем наличие multi_session_id, потом вызываем .get который не выкинет исключение, если его там нет. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get по привычке наверное Саша написал. |
||
multi_session_id = self.multi_session_id.browse(multi_session_id) | ||
vals['company_id'] = multi_session_id.company_id.id | ||
else: | ||
vals['company_id'] = self.env.user.company_id.id | ||
for config in self: | ||
result = super(PosConfig, config)._write(vals) | ||
return result | ||
|
||
|
||
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') | ||
|
@@ -57,17 +73,30 @@ class PosMultiSession(models.Model): | |
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) | ||
|
||
@api.multi | ||
@api.model | ||
def action_set_default_multi_session(self): | ||
""" | ||
during installation of the module set default multi-session | ||
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 | ||
""" | ||
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 there are POSes with the company then we need to create default multi-session | ||
if configs: | ||
# Create default multi-session for current company | ||
multi_session = self.create({ | ||
'name': 'Default Multi Session (%s)' % company.name, | ||
'multi_session_active': False, | ||
'company_id': company.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 | ||
}) | ||
|
||
@api.multi | ||
def name_get(self): | ||
|
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -88,6 +88,29 @@ | |
</div> | ||
</div> | ||
</xpath> | ||
<xpath expr="//field[@name='journal_id']/../../../../.." position="after"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Попроще точно ничего нельзя сделать?) |
||
<h2 attrs="{'invisible': [('is_installed_account_accountant', '=', True)]}">Accounting</h2> | ||
<div class="row mt16 o_settings_container" attrs="{'invisible': [('is_installed_account_accountant', '=', True)]}"> | ||
<div class="col-xs-12 col-md-6 o_setting_box"> | ||
<div class="o_setting_right_pane"> | ||
<label string="Journal Entries"/> | ||
<div class="text-muted"> | ||
Configuration for journal entries of PoS orders | ||
</div> | ||
<div class="content-group"> | ||
<div class="row mt16" title="Whenever you close a session, one entry is generated in the following accounting journal for all the orders not invoiced. Invoices are recorded in accounting separately."> | ||
<label string="Sales Journal" for="journal_id" class="col-md-3 o_light_label" widget="selection"/> | ||
<field name="journal_id"/> | ||
</div> | ||
<div class="row" groups="account.group_account_user" title="Get one journal item per product rather than one journal item per receipt line. This works for any anonymous order. If the customer is set on the order, one journal item is created for each receipt line. This option is recommended for an easy review of your journal entries when managing lots of orders."> | ||
<label string="Group Journal Items" for="group_by" class="col-md-3 o_light_label"/> | ||
<field name="group_by"/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍