Browse Source

[FIX] Tests and use related field instead of computed

pull/450/head
Iván Todorovich 5 years ago
parent
commit
3a33f26b0c
  1. 3
      pos_customer_required/__manifest__.py
  2. 14
      pos_customer_required/demo/pos_config.xml
  3. 11
      pos_customer_required/models/pos_config.py
  4. 19
      pos_customer_required/models/pos_order.py
  5. 2
      pos_customer_required/tests/test_pos.py
  6. 2
      pos_customer_required/views/pos_order_view.xml

3
pos_customer_required/__manifest__.py

@ -21,8 +21,5 @@
'views/pos_config_view.xml', 'views/pos_config_view.xml',
'views/pos_order_view.xml', 'views/pos_order_view.xml',
], ],
'demo': [
'demo/pos_config.xml',
],
'installable': True, 'installable': True,
} }

14
pos_customer_required/demo/pos_config.xml

@ -1,14 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<!-- POS Config: Require Customer(Required before starting the order) -->
<record id="point_of_sale.pos_config_main" model="pos.config">
<field name="require_customer">order</field>
</record>
</odoo>

11
pos_customer_required/models/pos_config.py

@ -11,16 +11,15 @@ from odoo import fields, models
class PosConfig(models.Model): class PosConfig(models.Model):
_inherit = 'pos.config' _inherit = 'pos.config'
_REQUIRE_CUSTOMER_KEYS = [
require_customer = fields.Selection([
('no', 'Optional'), ('no', 'Optional'),
('payment', 'Required before paying'), ('payment', 'Required before paying'),
('order', 'Required before starting the order'), ('order', 'Required before starting the order'),
]
require_customer = fields.Selection(
selection=_REQUIRE_CUSTOMER_KEYS,
],
string='Require Customer', string='Require Customer',
default='no',
help="Require customer for orders in this point of sale:\n" help="Require customer for orders in this point of sale:\n"
"* 'Optional' (customer is optional);\n" "* 'Optional' (customer is optional);\n"
"* 'Required before paying';\n" "* 'Required before paying';\n"
"* 'Required before starting the order';")
"* 'Required before starting the order';",
)

19
pos_customer_required/models/pos_order.py

@ -11,24 +11,13 @@ from odoo import fields, models, exceptions, api, _
class PosOrder(models.Model): class PosOrder(models.Model):
_inherit = 'pos.order' _inherit = 'pos.order'
@api.multi
@api.depends('session_id.config_id.require_customer')
def compute_require_customer(self):
for order in self:
order.require_customer = (
order.session_id.config_id.require_customer == 'order')
require_customer = fields.Boolean(
compute='compute_require_customer', string='Require customer',
help="True if a customer is required to begin the order.\n"
"See the PoS Config to change this setting")
require_customer = fields.Selection(
related='session_id.config_id.require_customer',
)
@api.constrains('partner_id', 'require_customer') @api.constrains('partner_id', 'require_customer')
def _check_partner(self): def _check_partner(self):
for rec in self: for rec in self:
if (
rec.session_id.config_id.require_customer == 'order' and
not rec.partner_id
):
if rec.require_customer != 'no' and not rec.partner_id:
raise exceptions.ValidationError(_( raise exceptions.ValidationError(_(
'Customer is required for this order and is missing.')) 'Customer is required for this order and is missing.'))

2
pos_customer_required/tests/test_pos.py

@ -6,7 +6,7 @@ from odoo import exceptions
class TestPosRequireCustomer(common.TransactionCase): class TestPosRequireCustomer(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestPosRequireCustomer, self).setUp() super(TestPosRequireCustomer, self).setUp()
self.pos_config = self.env.ref('point_of_sale.pos_config_main')
self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
def test_customer_not_required(self): def test_customer_not_required(self):
self.pos_config.require_customer = 'no' self.pos_config.require_customer = 'no'

2
pos_customer_required/views/pos_order_view.xml

@ -20,7 +20,7 @@
<field name="require_customer" invisible="1"/> <field name="require_customer" invisible="1"/>
</xpath> </xpath>
<xpath expr="//field[@name='partner_id']" position="attributes"> <xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="attrs">{'readonly': [('state','=','invoiced')], 'required': [('require_customer','=',True)]}</attribute>
<attribute name="attrs">{'readonly': [('state', '=', 'invoiced')], 'required': [('require_customer', '!=', 'no')]}</attribute>
</xpath> </xpath>
</field> </field>
</record> </record>

Loading…
Cancel
Save