From 2cc09e86afad709cc13e3a686afb0687b4752b3f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 4 Mar 2015 14:00:42 +0100 Subject: [PATCH 1/3] [FIX] web: on_change event on one2many fields was not fired if an attribute is mandatory (courtesy of Christophe Matthieu) opw: 626974 --- addons/web/static/src/js/view_form.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 1eef15a051b..52065001693 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3873,8 +3873,8 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ this.records .bind('add', this.proxy("changed_records")) - .bind('edit', this.proxy("changed_records")) .bind('remove', this.proxy("changed_records")); + this.on('save:after', this, this.proxy("changed_records")); }, start: function () { var ret = this._super(); @@ -3891,7 +3891,6 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ if (!this.fields_view || !this.editable()){ return true; } - var r; if (_.isEmpty(this.records.records)){ return true; } @@ -3902,9 +3901,8 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ current_values[field.name] = field.get('value'); }); var valid = _.every(this.records.records, function(record){ - r = record; _.each(self.editor.form.fields, function(field){ - field.set_value(r.attributes[field.name]); + field.set_value(record.attributes[field.name]); }); return _.every(self.editor.form.fields, function(field){ field.process_modifiers(); @@ -5477,11 +5475,11 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ calc_domain: function() { var d = instance.web.pyeval.eval('domain', this.build_domain()); var domain = []; //if there is no domain defined, fetch all the records - + if (d.length) { domain = ['|',['id', '=', this.get('value')]].concat(d); } - + if (! _.isEqual(domain, this.get("evaluated_selection_domain"))) { this.set("evaluated_selection_domain", domain); } From 6758b4cfc5ab5a9bf54c30aa14ed2dfd2fbf534d Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 10 Mar 2015 11:54:39 +0100 Subject: [PATCH 2/3] [FIX][REF] purchase: prevent confirming order if no stockable item After discussing with jco, we decided to keep it simple and have a coherent behavior between different versions, we then changed the behavior from the one of jbefficient PR at https://github.com/odoo-dev/odoo/commit/92adf673f7bed26b89b441b8fcd4d4061d685fb3. --- addons/purchase/purchase.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index e3b0fa5bfd9..8059e2d7788 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -149,19 +149,6 @@ class purchase_order(osv.osv): limit=1) return res and res[0] or False - def _has_non_stockable_item(self, cr, uid, ids, *args): - res = dict.fromkeys(ids, False) - for order in self.browse(cr, uid, ids): - for order_line in order.order_line: - if ( - not order_line.product_id - or - order_line.product_id - and order_line.product_id.type not in ('product', 'consu') - ): - res[order.id] = True - return res - STATE_SELECTION = [ ('draft', 'Draft PO'), ('sent', 'RFQ Sent'), @@ -237,7 +224,6 @@ class purchase_order(osv.osv): 'create_uid': fields.many2one('res.users', 'Responsible'), 'company_id': fields.many2one('res.company','Company',required=True,select=1, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}), 'journal_id': fields.many2one('account.journal', 'Journal'), - 'has_non_stockable_item': fields.function(_has_non_stockable_item, method=True, type='boolean', string='Contains a non-stockable item'), } _defaults = { 'date_order': fields.date.context_today, @@ -485,10 +471,10 @@ class purchase_order(osv.osv): for po in self.browse(cr, uid, ids, context=context): if not po.order_line: raise osv.except_osv(_('Error!'),_('You cannot confirm a purchase order without any purchase order line.')) - if po.invoice_method == 'picking' and po.has_non_stockable_item is True: + if po.invoice_method == 'picking' and not any([l.product_id and l.product_id.type in ('product', 'consu') for l in po.order_line]): raise osv.except_osv( _('Error!'), - _("You cannot confirm a purchase order with Invoice Control Method 'Based on incoming shipments' that contains non-stockable items.")) + _("You cannot confirm a purchase order with Invoice Control Method 'Based on incoming shipments' that doesn't contain any stockable item.")) for line in po.order_line: if line.state=='draft': todo.append(line.id) From a5e32690b054d3c5d68bc33bf1bf7336d075dc2b Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 6 Mar 2015 00:29:02 +0100 Subject: [PATCH 3/3] [FIX] tests: UTC used in test when it should not MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test for account followup use UTC time, but the default `date_maturity` and `date_due` of an account invoice come from fields.Date.context_today`. One failing test for project_timesheet also used `today` instead of `context_today`. So depending on the test user timezone, an error of one day (if UTC time and user time are on different day) occured which failed the tests. For example: * user has GMT+1 timezone, test fails 0:00am–1:00am (11:00pm-0:00am in UTC) * user has GMT+3 timezone, test fails 0:00am–3:00am (9:00pm-0:00am in UTC) This fix removes UTC use in the tests. --- .../tests/test_account_followup.py | 26 +++++++++---------- .../project_timesheet/test/work_timesheet.yml | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/account_followup/tests/test_account_followup.py b/addons/account_followup/tests/test_account_followup.py index 8648c2b7621..0d7b135f65a 100644 --- a/addons/account_followup/tests/test_account_followup.py +++ b/addons/account_followup/tests/test_account_followup.py @@ -6,6 +6,7 @@ from openerp import tools from openerp.tests.common import TransactionCase from openerp import netsvc +from openerp.osv import fields class TestAccountFollowup(TransactionCase): def setUp(self): @@ -48,14 +49,15 @@ class TestAccountFollowup(TransactionCase): wf_service.trg_validate(uid, 'account.invoice', self.invoice_id, 'invoice_open', cr) self.voucher = self.registry("account.voucher") + + self.current_date = datetime.datetime.strptime(fields.date.context_today(self.user, cr, uid, context={}), tools.DEFAULT_SERVER_DATE_FORMAT) def test_00_send_followup_after_3_days(self): """ Send follow up after 3 days and check nothing is done (as first follow-up level is only after 15 days)""" cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=3) - result = current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) @@ -65,33 +67,32 @@ class TestAccountFollowup(TransactionCase): def run_wizard_three_times(self): cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=40) - result = current_date + delta + result = self.current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id, }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) def test_01_send_followup_later_for_upgrade(self): """ Send one follow-up after 15 days to check it upgrades to level 1""" cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=15) - result = current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, { 'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.assertEqual(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id.id, self.first_followup_line_id, "Not updated to the correct follow-up level") @@ -102,7 +103,7 @@ class TestAccountFollowup(TransactionCase): self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action, "Call the customer on the phone! ", "Manual action not set") self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action_date, - datetime.datetime.utcnow().strftime(tools.DEFAULT_SERVER_DATE_FORMAT)) + self.current_date.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)) def test_03_filter_on_credit(self): """ Check the partners can be filtered on having credits """ @@ -139,9 +140,8 @@ class TestAccountFollowup(TransactionCase): """Run wizard until manual action, pay the invoice and check that partner has no follow-up level anymore and after running the wizard the action is empty""" cr, uid = self.cr, self.uid self.test_02_check_manual_action() - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=1) - result = current_date + delta + result = self.current_date + delta self.invoice.pay_and_reconcile(cr, uid, [self.invoice_id], 1000.0, self.pay_account_id, self.period_id, self.journal_id, self.pay_account_id, self.period_id, self.journal_id, diff --git a/addons/project_timesheet/test/work_timesheet.yml b/addons/project_timesheet/test/work_timesheet.yml index d8367e9f7d8..9c28ec3a76f 100644 --- a/addons/project_timesheet/test/work_timesheet.yml +++ b/addons/project_timesheet/test/work_timesheet.yml @@ -12,8 +12,8 @@ I check Timesheet line for employee in current Timesheet - !python {model: hr.analytic.timesheet}: | - import datetime - start = (datetime.date.today().strftime('%Y-%m-%d')) + from openerp.osv import fields + start = fields.date.context_today(self, cr, uid, context=context) task_work = self.search(cr, uid, [("name","=","Social network integration: Test Timesheet records")],context)[0] task_ids = self.browse(cr, uid, task_work, context) assert task_ids.user_id.id == ref("base.user_demo"), 'Error, The User in Timesheet is not Correct'