diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index bea0c302bac..c666c91d481 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -606,14 +606,45 @@ class pos_order(osv.osv): 'journal': ui_paymentline['journal_id'], } + # This deals with orders that belong to a closed session. In order + # to recover from this we: + # - assign the order to another compatible open session + # - if that doesn't exist, create a new one + def _get_valid_session(self, cr, uid, order, context=None): + session = self.pool.get('pos.session') + closed_session = session.browse(cr, uid, order['pos_session_id'], context=context) + open_sessions = session.search(cr, uid, [('state', '=', 'opened'), + ('config_id', '=', closed_session.config_id.id), + ('user_id', '=', closed_session.user_id.id)], + limit=1, order="start_at DESC", context=context) + + if open_sessions: + return open_sessions[0] + else: + new_session_id = session.create(cr, uid, { + 'config_id': closed_session.config_id.id, + }, context=context) + new_session = session.browse(cr, uid, new_session_id, context=context) + + # bypass opening_control (necessary when using cash control) + new_session.signal_workflow('open') + + return new_session_id + def _process_order(self, cr, uid, order, context=None): + session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context) + + if session.state == 'closing_control' or session.state == 'closed': + session_id = self._get_valid_session(cr, uid, order, context=context) + session = self.pool.get('pos.session').browse(cr, uid, session_id, context=context) + order['pos_session_id'] = session_id + order_id = self.create(cr, uid, self._order_fields(cr, uid, order, context=context),context) journal_ids = set() for payments in order['statement_ids']: self.add_payment(cr, uid, order_id, self._payment_fields(cr, uid, payments[2], context=context), context=context) journal_ids.add(payments[2]['journal_id']) - session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context) if session.sequence_number <= order['sequence_number']: session.write({'sequence_number': order['sequence_number'] + 1}) session.refresh() diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index dd3f90c95c1..466a90fa639 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -141,7 +141,7 @@
  • diff --git a/openerp/addons/test_inherit/ir.model.access.csv b/openerp/addons/test_inherit/ir.model.access.csv index 9118525cff3..fcf5366a425 100644 --- a/openerp/addons/test_inherit/ir.model.access.csv +++ b/openerp/addons/test_inherit/ir.model.access.csv @@ -1,3 +1,4 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" access_test_inherit_mother,access_test_inherit_mother,model_test_inherit_mother,,1,1,1,1 access_test_inherit_daughter,access_test_inherit_daughter,model_test_inherit_daughter,,1,1,1,1 +access_test_inherit_property,access_test_inherit_property,model_test_inherit_property,,1,1,1,1 diff --git a/openerp/addons/test_inherit/models.py b/openerp/addons/test_inherit/models.py index f783b42fb4c..0875c4fed5a 100644 --- a/openerp/addons/test_inherit/models.py +++ b/openerp/addons/test_inherit/models.py @@ -78,3 +78,35 @@ class res_partner(models.Model): # define a one2many field based on the inherited field partner_id daughter_ids = fields.One2many('test.inherit.daughter', 'partner_id') + + +# Check the overriding of property fields by non-property fields. +# Contribution by Adrien Peiffer (ACSONE). +class test_inherit_property(models.Model): + _name = 'test.inherit.property' + + _columns = { + 'name': osv.fields.char('Name', required=True), + 'property_foo': osv.fields.property(string='Foo', type='integer'), + 'property_bar': osv.fields.property(string='Bar', type='integer'), + } + +class test_inherit_property(models.Model): + _inherit = 'test.inherit.property' + + @api.multi + def _get_foo(self, name, arg): + return dict.fromkeys(self.ids, 42) + + _columns = { + # override property_foo with an old-api function field + 'property_foo': osv.fields.function(_get_foo, type='integer', string='Foo'), + } + + # override property_bar with a new-api computed field + property_bar = fields.Integer(compute='_compute_bar', company_dependent=False) + + @api.multi + def _compute_bar(self): + for record in self: + record.property_bar = 42 diff --git a/openerp/addons/test_inherit/tests/test_inherit.py b/openerp/addons/test_inherit/tests/test_inherit.py index 56a0b319794..ddf5d1424a0 100644 --- a/openerp/addons/test_inherit/tests/test_inherit.py +++ b/openerp/addons/test_inherit/tests/test_inherit.py @@ -76,3 +76,20 @@ class test_inherits(common.TransactionCase): # search the partner from the daughter record partners = self.env['res.partner'].search([('daughter_ids', 'in', daughter.ids)]) self.assertIn(partner_demo, partners) + + +class test_override_property(common.TransactionCase): + + def test_override_with_function_field(self): + """ test overriding a property field by a function field """ + record = self.env['test.inherit.property'].create({'name': "Stuff"}) + # record.property_foo is not a property field + self.assertEqual(record.property_foo, 42) + self.assertFalse(type(record).property_foo.company_dependent) + + def test_override_with_computed_field(self): + """ test overriding a property field by a computed field """ + record = self.env['test.inherit.property'].create({'name': "Stuff"}) + # record.property_bar is not a property field + self.assertEqual(record.property_bar, 42) + self.assertFalse(type(record).property_bar.company_dependent) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index a1f06219725..61d6114dcb3 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -1399,6 +1399,7 @@ class function(_column): def to_field_args(self): args = super(function, self).to_field_args() args['store'] = bool(self.store) + args['company_dependent'] = False if self._type in ('float',): args['digits'] = self._digits_compute or self._digits elif self._type in ('selection', 'reference'):