From f3573d844e0521dcff8954fb261759ef38986c85 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 12 Oct 2011 18:12:08 +0200 Subject: [PATCH 01/37] [IMP] use login_env for login bzr revid: chs@openerp.com-20111012161208-yto1rang9znmoh4i --- addons/web/common/session.py | 4 ++-- addons/web/controllers/main.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/web/common/session.py b/addons/web/common/session.py index e8027db8ea4..ef38fc6a154 100644 --- a/addons/web/common/session.py +++ b/addons/web/common/session.py @@ -58,8 +58,8 @@ class OpenERPSession(object): self._login = login self._password = password - def login(self, db, login, password): - uid = self.proxy('common').login(db, login, password) + def login(self, db, login, password, env): + uid = self.proxy('common').login_env(db, login, password, 'web', env) self.bind(db, uid, login, password) if uid: self.get_context() diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7ca80fbfdec..2432edc71ea 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -5,6 +5,7 @@ import base64 import csv import glob import itertools +import logging import operator import os import re @@ -21,6 +22,8 @@ import babel.messages.pofile import web.common openerpweb = web.common.http +_logger = logging.getLogger(__name__) + #---------------------------------------------------------- # OpenERP Web web Controllers #---------------------------------------------------------- @@ -263,7 +266,13 @@ class Session(openerpweb.Controller): @openerpweb.jsonrequest def login(self, req, db, login, password): - req.session.login(db, login, password) + wsgienv = req.httprequest.environ + env = dict( + host='%s://%s' % (wsgienv['wsgi.url_scheme'], wsgienv['HTTP_HOST']), + referrer=wsgienv.get('HTTP_REFERER'), + REMOTE_ADDR=wsgienv['REMOTE_ADDR'], + ) + req.session.login(db, login, password, env) ctx = req.session.get_context() if req.session._uid else {} return { From 9ecff1245aedd5d7a3d6d565389d35d9920acf59 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 20 Oct 2011 16:42:17 +0200 Subject: [PATCH 02/37] [IMP] account_voucher: onchange_partner_id small refactoring + improved the splitting of the amount by existing voucher lines bzr revid: qdp-launchpad@openerp.com-20111020144217-t4owndjuntdeuts9 --- addons/account_voucher/account_voucher.py | 91 ++++++++++--------- addons/account_voucher/invoice.py | 5 +- .../voucher_payment_receipt_view.xml | 30 +++--- 3 files changed, 68 insertions(+), 58 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 38af59009d8..d2f9d230fbd 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -427,36 +427,31 @@ class account_voucher(osv.osv): if date: context_multi_currency.update({'date': date}) - line_pool = self.pool.get('account.voucher.line') - line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False - if line_ids: - line_pool.unlink(cr, uid, line_ids) - currency_pool = self.pool.get('res.currency') move_line_pool = self.pool.get('account.move.line') partner_pool = self.pool.get('res.partner') journal_pool = self.pool.get('account.journal') + line_pool = self.pool.get('account.voucher.line') + #get default values vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context) vals = vals.get('value') - - journal = journal_pool.browse(cr, uid, journal_id, context=context) currency_id = vals.get('currency_id', currency_id) default = { 'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id':currency_id}, } - currency_id = currency_id or journal.company_id.currency_id.id + + #drop existing lines + line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False + if line_ids: + line_pool.unlink(cr, uid, line_ids) if not partner_id: return default - if not partner_id and ids: - line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) - if line_ids: - line_pool.unlink(cr, uid, line_ids) - return default - + journal = journal_pool.browse(cr, uid, journal_id, context=context) partner = partner_pool.browse(cr, uid, partner_id, context=context) + currency_id = currency_id or journal.company_id.currency_id.id account_id = False if journal.type in ('sale','sale_refund'): account_id = partner.property_account_receivable.id @@ -484,64 +479,78 @@ class account_voucher(osv.osv): ids = move_line_pool.search(cr, uid, [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)], context=context) else: ids = context['move_line_ids'] + invoice_id = context.get('invoice_id', False) + company_currency = journal.company_id.currency_id.id + move_line_found = False + + #order the lines by most old first ids.reverse() moves = move_line_pool.browse(cr, uid, ids, context=context) - #company_currency = journal.company_id.currency_id.id - #if company_currency != currency_id and ttype == 'payment': - # total_debit = currency_pool.compute(cr, uid, currency_id, company_currency, total_debit, context=context_multi_currency) - #elif company_currency != currency_id and ttype == 'receipt': - # total_credit = currency_pool.compute(cr, uid, currency_id, company_currency, total_credit, context=context_multi_currency) - - company_currency = journal.company_id.currency_id.id for line in moves: if line.credit and line.reconcile_partial_id and ttype == 'receipt': continue if line.debit and line.reconcile_partial_id and ttype == 'payment': continue + if invoice_id: + if line.invoice.id == invoice_id: + #if the invoice linked to the voucher line is equal to the invoice_id in context + #then we assign the amount on that line, whatever the other voucher lines + move_line_found = line.id + break + elif currency_id == company_currency: + #otherwise treatments is the same but with other field names + if line.amount_residual == price: + #if the amount residual is equal the amount voucher, we assign it to that voucher + #line, whatever the other voucher lines + move_line_found = line.id + break + #otherwise we will split the voucher amount on each line (by most old first) + total_credit += line.credit or 0.0 + total_debit += line.debit or 0.0 + elif currency_id == line.currency_id.id: + if line.amount_residual_currency == price: + move_line_found = line.id + break + total_credit += line.credit and line.amount_currency or 0.0 + total_debit += line.debit and line.amount_currency or 0.0 - if line.currency_id and currency_id==line.currency_id.id: - total_credit += line.amount_currency <0 and -line.amount_currency or 0.0 - total_debit += line.amount_currency >0 and line.amount_currency or 0.0 - else: - total_credit += currency_pool.compute(cr, uid, company_currency, currency_id, line.credit or 0.0) - total_debit += currency_pool.compute(cr, uid, company_currency, currency_id, line.debit or 0.0) - + #voucher line creation for line in moves: if line.credit and line.reconcile_partial_id and ttype == 'receipt': continue if line.debit and line.reconcile_partial_id and ttype == 'payment': continue - if line.currency_id and currency_id==line.currency_id.id: amount_original = abs(line.amount_currency) amount_unreconciled = abs(line.amount_residual_currency) else: amount_original = currency_pool.compute(cr, uid, company_currency, currency_id, line.credit or line.debit or 0.0) amount_unreconciled = currency_pool.compute(cr, uid, company_currency, currency_id, abs(line.amount_residual)) - - #original_amount = line.credit or line.debit or 0.0 - #amount_unreconciled = currency_pool.compute(cr, uid, line.currency_id and line.currency_id.id or company_currency, currency_id, abs(line.amount_residual_currency), context=context_multi_currency) rs = { 'name':line.move_id.name, 'type': line.credit and 'dr' or 'cr', 'move_line_id':line.id, 'account_id':line.account_id.id, 'amount_original': amount_original, + 'amount': (move_line_found == line.id) and min(price, amount_unreconciled) or 0.0, 'date_original':line.date, 'date_due':line.date_maturity, 'amount_unreconciled': amount_unreconciled, - } - if line.credit: - amount = min(amount_unreconciled, total_debit) - rs['amount'] = amount - total_debit -= amount - else: - amount = min(amount_unreconciled, total_credit) - rs['amount'] = amount - total_credit -= amount + #split voucher amount by most old first, but only for lines in the same currency + if not move_line_found: + line_currency_id = line.currency_id and line.currency_id.id or company_currency + if currency_id == line_currency_id: + if line.credit: + amount = min(amount_unreconciled, abs(total_debit)) + rs['amount'] = amount + total_debit -= amount + else: + amount = min(amount_unreconciled, abs(total_credit)) + rs['amount'] = amount + total_credit -= amount default['value']['line_ids'].append(rs) if rs['type'] == 'cr': diff --git a/addons/account_voucher/invoice.py b/addons/account_voucher/invoice.py index 0230cac1009..b108bc14fe3 100644 --- a/addons/account_voucher/invoice.py +++ b/addons/account_voucher/invoice.py @@ -45,10 +45,11 @@ class invoice(osv.osv): 'close_after_process': True, 'invoice_type':inv.type, 'invoice_id':inv.id, - 'default_type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment' + 'default_type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment', + 'type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment' } } invoice() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 9c8bdffb35d..0ddc868cb45 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -74,14 +74,14 @@
- - + + - + - + - + @@ -137,15 +137,15 @@ - + - + @@ -279,19 +279,19 @@ - + + on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/> - + @@ -303,7 +303,7 @@ - + - + From d049a25fa5f5053014d5930da14818fd056a1cac Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Fri, 21 Oct 2011 12:21:03 +0530 Subject: [PATCH 03/37] [FIX] Fixed the issue of buttons 'First', '<', '>', 'Last' would be nice at the bottom, too lp bug: https://launchpad.net/bugs/878106 fixed bzr revid: tpa@tinyerp.com-20111021065103-slbb7n124cuyvwhm --- addons/web/static/src/xml/base.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 7720ae2d38b..c3f15cf281c 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -612,6 +612,23 @@ + + + + + + + + + + + + From f3f582eaa0a37bcc47b3abaf643baa1c12508927 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 09:22:40 +0200 Subject: [PATCH 04/37] [IMP] add debug keys to nonliteral domains and contexts, simplify keyscheck for validity (and make it look like python code) bzr revid: xmo@openerp.com-20111021072240-82wly4vbkmmqn15z --- addons/web/common/nonliterals.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/web/common/nonliterals.py b/addons/web/common/nonliterals.py index 42dbe9cfd4f..f6e81894a4c 100644 --- a/addons/web/common/nonliterals.py +++ b/addons/web/common/nonliterals.py @@ -21,12 +21,14 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder): if isinstance(object, Domain): return { '__ref': 'domain', - '__id': object.key + '__id': object.key, + '__debug': object.get_domain_string() } elif isinstance(object, Context): return { '__ref': 'context', - '__id': object.key + '__id': object.key, + '__debug': object.get_context_string() } elif isinstance(object, CompoundDomain): return { @@ -42,7 +44,7 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder): } raise TypeError('Could not encode unknown non-literal %s' % object) -_ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains', +_ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains', '__debug', '__contexts', '__eval_context', 'own_values']) def non_literal_decoder(dct): @@ -53,8 +55,8 @@ def non_literal_decoder(dct): ``own_values`` dict key. """ if '__ref' in dct: - for x in dct.keys(): - if not x in _ALLOWED_KEYS: + for x in dct: + if x not in _ALLOWED_KEYS: raise ValueError("'%s' key not allowed in non literal domain/context" % x) if dct['__ref'] == 'domain': domain = Domain(None, key=dct['__id']) From 5857483a5f7a98c6e36bb318851e2444221aa8ea Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 10:10:43 +0200 Subject: [PATCH 05/37] [REM] stock: nonsensical context on list view action buttons for splitting orders in production lots lp bug: https://launchpad.net/bugs/878142 fixed bzr revid: xmo@openerp.com-20111021081043-zzhi6q5oa2solnzj --- addons/stock/stock_view.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 8b96a613f6d..6452960c2cd 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1384,7 +1384,6 @@ + - - - - - - - - - - @@ -612,25 +598,26 @@ - - - - - - - - - - - - + + + + + + + + + + + + + From 4da3e5d354f9fa84ef30d371fe60e7fa301b001f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 13:50:18 +0200 Subject: [PATCH 10/37] [FIX] tests runner: changed file names bzr revid: xmo@openerp.com-20111021115018-0qbmhwhcjmckco0w --- addons/web/static/test/formats.js | 2 +- addons/web/static/test/test.html | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/web/static/test/formats.js b/addons/web/static/test/formats.js index 331725dd9a5..57ffd981ed8 100644 --- a/addons/web/static/test/formats.js +++ b/addons/web/static/test/formats.js @@ -51,4 +51,4 @@ $(document).ready(function () { var val = openerp.web.parse_value(str, {type:"float"}); equal(val, -134112.1234); }); -}); \ No newline at end of file +}); diff --git a/addons/web/static/test/test.html b/addons/web/static/test/test.html index 38237a0600a..e45b982fa9e 100644 --- a/addons/web/static/test/test.html +++ b/addons/web/static/test/test.html @@ -21,7 +21,7 @@ - + @@ -31,10 +31,10 @@ - - + + From 0259bb76299927f7a15566ac79a389effeeb3e20 Mon Sep 17 00:00:00 2001 From: vishmita Date: Fri, 21 Oct 2011 17:36:45 +0530 Subject: [PATCH 11/37] [FIX] FF issues in dataset limit. lp bug: https://launchpad.net/bugs/876603 fixed bzr revid: vja@vja-desktop-20111021120645-qx0en9plxihle0dj --- addons/web/static/src/js/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 475dbe5421c..069506586ad 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -493,7 +493,7 @@ openerp.web.DataSetStatic = openerp.web.DataSet.extend({ offset = options.offset || 0, limit = options.limit || false, fields = fields || false; - var end_pos = limit && limit !== -1 ? offset + limit : undefined; + var end_pos = limit && limit !== -1 ? offset + limit : this.ids.length; return this.read_ids(this.ids.slice(offset, end_pos), fields, callback); }, set_ids: function (ids) { From 01897c8aa6b946492eeaba1595e7e925837527b7 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 14:07:41 +0200 Subject: [PATCH 12/37] [FIX] completely broken float formatting when leading 0 Formatting converted the decimal part into an integer, dropping all leading 0s and failing to reinsert them. The conversion also lead to compounded errors, casting 0.1100 into 0.10999 (something like that). Replace this by a straight float formatting via _.sprintf and the slicing of the decimal part from the resulting string (Math.abs and %1 clamp the value to format to the [0, 1[ range, ensuring we just need to slice off the first two characters). Also add some tests. lp bug: https://launchpad.net/bugs/879355 fixed bzr revid: xmo@openerp.com-20111021120741-813im5bzup7vho1f --- addons/web/static/src/js/formats.js | 11 +++++++---- addons/web/static/test/formats.js | 12 ++++++++++++ addons/web/static/test/test.html | 3 --- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 94b2c7085db..3ab972f7a86 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -28,10 +28,13 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) { case 'float': var precision = descriptor.digits ? descriptor.digits[1] : 2; var int_part = Math.floor(value); - var dec_part = Math.abs(Math.floor((value % 1) * Math.pow(10, precision))); - return _.sprintf('%d%s%d', - int_part, - openerp.web._t.database.parameters.decimal_point, dec_part); + var dec_part = _.sprintf( + '%.' + precision + 'f', + Math.abs(value) % 1).substring(2); + return _.sprintf('%d%s%s', + int_part, + openerp.web._t.database.parameters.decimal_point, + dec_part); case 'float_time': return _.sprintf("%02d:%02d", Math.floor(value), diff --git a/addons/web/static/test/formats.js b/addons/web/static/test/formats.js index 57ffd981ed8..3c3c6b06e72 100644 --- a/addons/web/static/test/formats.js +++ b/addons/web/static/test/formats.js @@ -27,6 +27,18 @@ $(document).ready(function () { var fl = 12.1234; var str = openerp.web.format_value(fl, {type:"float"}); equal(str, "12.12"); + equal(openerp.web.format_value(12.02, {type: 'float'}), + '12.02'); + equal(openerp.web.format_value(0.0002, {type: 'float', digits: [1, 3]}), + '0.000'); + equal(openerp.web.format_value(0.0002, {type: 'float', digits: [1, 4]}), + '0.0002'); + equal(openerp.web.format_value(0.0002, {type: 'float', digits: [1, 6]}), + '0.000200'); + equal(openerp.web.format_value(1, {type: 'float', digits: [1, 6]}), + '1.000000'); + equal(openerp.web.format_value(1, {type: 'float'}), + '1.00'); }); test("parse_datetime", function () { var val = openerp.web.str_to_datetime("2009-05-04 12:34:23"); diff --git a/addons/web/static/test/test.html b/addons/web/static/test/test.html index e45b982fa9e..f6248e705c0 100644 --- a/addons/web/static/test/test.html +++ b/addons/web/static/test/test.html @@ -33,9 +33,6 @@ -

OpenERP web Test Suite

From 0e9d7318fc2c47a1b3fe495bf12f90c968e36ea9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 14:22:56 +0200 Subject: [PATCH 13/37] [FIX] float formatting in form view should take digits/@digits in account lp bug: https://launchpad.net/bugs/879346 fixed bzr revid: xmo@openerp.com-20111021122256-ld3gm8u3yt4kdn71 --- addons/web/static/src/js/view_form.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index f8168d21466..8736f2d69e3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1233,6 +1233,19 @@ openerp.web.form.FieldUrl = openerp.web.form.FieldChar.extend({ }); openerp.web.form.FieldFloat = openerp.web.form.FieldChar.extend({ + init: function (view, node) { + this._super(view, node); + if (node.attrs.digits) { + this.parse_digits(node.attrs.digits); + } else { + this.digits = view.fields_view.fields[node.attrs.name].digits; + } + }, + parse_digits: function (digits_attr) { + // could use a Python parser instead. + var match = /^\s*[\(\[](\d+),\s*(\d+)/.exec(digits_attr); + return [parseInt(match[1], 10), parseInt(match[2], 10)]; + }, set_value: function(value) { if (value === false || value === undefined) { // As in GTK client, floats default to 0 From 88c75e94d381f75009c9c2719ff16234d5792bcb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Oct 2011 15:03:59 +0200 Subject: [PATCH 14/37] [FIX] project_issue: incorrect invisible attrs domain on list view field lp bug: https://launchpad.net/bugs/879376 fixed bzr revid: xmo@openerp.com-20111021130359-vz9s4x46od2p9zwf --- addons/project_issue/project_issue_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/project_issue/project_issue_view.xml b/addons/project_issue/project_issue_view.xml index 916c67b15d4..00e6a00c163 100644 --- a/addons/project_issue/project_issue_view.xml +++ b/addons/project_issue/project_issue_view.xml @@ -188,7 +188,7 @@ - + From cdac09e3dce901458f87ed5eca4d10a2981c9938 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 24 Oct 2011 10:40:05 +0200 Subject: [PATCH 34/37] [fix] css problem in database screen when we use a too high resolution bzr revid: nicolas.vanhoren@openerp.com-20111024084005-et884p0px0l08ge8 --- addons/web/static/src/css/base.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 6872b921435..1f8796b539c 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -159,7 +159,7 @@ body.openerp, .openerp textarea, .openerp input, .openerp select, .openerp optio } .db_container { - width: 15%; + width: 196px; background: #666666; } From 66c0054a5174029222e0cc24ce9a56c9d2ac9b88 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 24 Oct 2011 10:55:54 +0200 Subject: [PATCH 35/37] [IMP] Kanban: set appropriate debug property on qweb instance bzr revid: fme@openerp.com-20111024085554-ya7vpm2gpqqi5shj --- addons/web_kanban/static/src/js/kanban.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 11d675a5705..82b085d9749 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -16,6 +16,7 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({ this.all_display_data = false; this.groups = []; this.qweb = new QWeb2.Engine(); + this.qweb.debug = (window.location.search.indexOf('?debug') !== -1); this.aggregates = {}; this.NO_OF_COLUMNS = 3; this.form_dialog = new openerp.web.FormDialog(this, {}, this.options.action_views_ids.form, dataset).start(); From 62c52bf0c21f07a75734bb18872e3047f7191f67 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 24 Oct 2011 11:21:40 +0200 Subject: [PATCH 36/37] [FIX] Do not use node.parentElement (sorry all) lp bug: https://launchpad.net/bugs/879797 fixed bzr revid: fme@openerp.com-20111024092140-zvrtzmy9cppjyaj2 --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 4ed33341ea6..39a1ba7ef64 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1048,7 +1048,7 @@ openerp.web.qweb = new QWeb2.Engine(); openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); openerp.web.qweb.format_text_node = function(s) { // Note that 'this' is the Qweb Node of the text - var translation = this.node.parentElement.attributes['t-translation']; + var translation = this.node.parentNode.attributes['t-translation']; if (translation && translation.value === 'off') { return s; } From 3fd701e82a3d59c76663daa2ac080fc1cb3e6fcd Mon Sep 17 00:00:00 2001 From: "tfr@openerp.com" <> Date: Mon, 24 Oct 2011 11:48:12 +0200 Subject: [PATCH 37/37] [FIX] adapt sugarcrm-import with new mail system and new stage structure + Improve logging bzr revid: tfr@openerp.com-20111024094812-jts3o1re1o738fjw --- addons/import_base/import_framework.py | 31 +++++++++++------------ addons/import_sugarcrm/import_sugarcrm.py | 28 ++++++++++---------- addons/import_sugarcrm/sugar.py | 10 +++++++- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/addons/import_base/import_framework.py b/addons/import_base/import_framework.py index b558b24696f..1f627d2ad58 100644 --- a/addons/import_base/import_framework.py +++ b/addons/import_base/import_framework.py @@ -60,7 +60,7 @@ class import_framework(Thread): self.context = context or {} self.email = email_to_notify self.table_list = [] - self.logger = logging.getLogger('import_framework') + self.logger = logging.getLogger(module_name) self.initialize() """ @@ -165,6 +165,7 @@ class import_framework(Thread): data_i is a map external field_name => value and each data_i have a external id => in data_id['id'] """ + self.logger.info(' Importing %s into %s' % (table, model)) if not datas: return (0, 'No data found') mapping['id'] = 'id_new' @@ -187,8 +188,7 @@ class import_framework(Thread): model_obj = self.obj.pool.get(model) if not model_obj: raise ValueError(_("%s is not a valid model name") % model) - self.logger.debug(_("fields imported : ")) - self.logger.debug(fields) + self.logger.debug(_(" fields imported : ") + str(fields)) (p, r, warning, s) = model_obj.import_data(self.cr, self.uid, fields, res, mode='update', current_module=self.module_name, noupdate=True, context=self.context) for (field, field_name) in self_dependencies: self._import_self_dependencies(model_obj, field, datas) @@ -330,7 +330,6 @@ class import_framework(Thread): xml_ref = self.mapped_id_if_exist(model, domain_search, table, name) fields.append('id') data.append(xml_id) - obj.import_data(self.cr, self.uid, fields, [data], mode='update', current_module=self.module_name, noupdate=True, context=self.context) return xml_ref or xml_id @@ -385,7 +384,6 @@ class import_framework(Thread): res = self._resolve_dependencies(self.get_mapping()[table].get('dependencies', []), imported) result.extend(res) if to_import: - self.logger.debug(_("import : ") + table ) (position, warning) = self._import_table(table) result.append((table, position, warning)) imported.add(table) @@ -396,12 +394,13 @@ class import_framework(Thread): traceback.print_exc(file=sh) error = sh.getvalue() print error - finally: - self.cr.close() + self.date_ended = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") self._send_notification_email(result, error) + self.cr.close() + def _resolve_dependencies(self, dep, imported): """ import dependencies recursively @@ -414,7 +413,6 @@ class import_framework(Thread): res = self._resolve_dependencies(self.get_mapping()[dependency].get('dependencies', []), imported) result.extend(res) if to_import: - self.logger.debug("import dependency : " + dependency) r = self._import_table(dependency) (position, warning) = r result.append((dependency, position, warning)) @@ -422,15 +420,16 @@ class import_framework(Thread): return result def _send_notification_email(self, result, error): - if not self.email or not self.email[0]: + if not self.email: return False - - tools.email_send( - 'import@module.openerp', - self.email, - self.get_email_subject(result, error), - self.get_email_body(result, error), - ) + email_obj = self.obj.pool.get('mail.message') + email_id = email_obj.create(self.cr, self.uid, { + 'email_from' : 'import@module.openerp', + 'email_to' : self.email, + 'body_text' : self.get_email_body(result, error), + 'subject' : self.get_email_subject(result, error), + 'auto_delete' : True}) + email_obj.send(self.cr, self.uid, [email_id]) if error: self.logger.error(_("Import failed due to an unexpected error")) else: diff --git a/addons/import_sugarcrm/import_sugarcrm.py b/addons/import_sugarcrm/import_sugarcrm.py index b27748d48be..d5f487c5377 100644 --- a/addons/import_sugarcrm/import_sugarcrm.py +++ b/addons/import_sugarcrm/import_sugarcrm.py @@ -210,12 +210,12 @@ class sugar_import(import_framework): def get_email_mapping(self): return { - 'model' : 'mailgate.message', + 'model' : 'mail.message', 'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD, self.TABLE_OPPORTUNITY, self.TABLE_MEETING, self.TABLE_CALL], 'hook' : self.import_email, 'map' : { - 'name':'name', - 'history' : const("1"), + 'subject':'name', + 'state' : const('received'), 'date':'date_sent', 'email_from': 'from_addr_name', 'email_to': 'to_addrs_names', @@ -226,7 +226,9 @@ class sugar_import(import_framework): 'model': 'model', 'partner_id/.id': 'partner_id/.id', 'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'), - 'description': ppconcat('description', 'description_html'), + 'body_text': 'description', + 'body_html' : 'description_html', + } } @@ -575,10 +577,10 @@ class sugar_import(import_framework): } def get_opportunity_status(self, sugar_val): - fields = ['name', 'type'] + fields = ['name', 'case_default'] name = 'Opportunity_' + sugar_val['sales_stage'] - data = [sugar_val['sales_stage'], 'Opportunity'] - return self.import_object(fields, data, 'crm.case.stage', self.TABLE_STAGE, name, [('type', '=', 'opportunity'), ('name', 'ilike', sugar_val['sales_stage'])]) + data = [sugar_val['sales_stage'], '1'] + return self.import_object(fields, data, 'crm.case.stage', self.TABLE_STAGE, name, [('name', 'ilike', sugar_val['sales_stage'])]) def import_opportunity_contact(self, val): sugar_opportunities_contact = set(sugar.relation_search(self.context.get('port'), self.context.get('session_id'), 'Opportunities', module_id=val.get('id'), related_module='Contacts', query=None, deleted=None)) @@ -647,11 +649,11 @@ class sugar_import(import_framework): import lead """ def get_lead_status(self, sugar_val): - fields = ['name', 'type'] + fields = ['name', 'case_default'] name = 'lead_' + sugar_val.get('status', '') - data = [sugar_val.get('status', ''), 'lead'] - return self.import_object(fields, data, 'crm.case.stage', self.TABLE_STAGE, name, [('type', '=', 'lead'), ('name', 'ilike', sugar_val.get('status', ''))]) - + data = [sugar_val.get('status', ''), '1'] + return self.import_object(fields, data, 'crm.case.stage', self.TABLE_STAGE, name, [('name', 'ilike', sugar_val.get('status', ''))]) + lead_state = { 'New' : 'draft', 'Assigned':'open', @@ -1085,7 +1087,7 @@ class import_sugarcrm(osv.osv): scheduler Method """ context = {'username': args[4], 'password': args[5], 'url': args[3], 'instance_name': args[3]} - imp = sugar_import(self, cr, uid, args[2], "import_sugarcrm", [args[1]], context) + imp = sugar_import(self, cr, uid, args[2], "import_sugarcrm", args[1], context) imp.set_table_list(args[0]) imp.start() return True @@ -1129,7 +1131,7 @@ class import_sugarcrm(osv.osv): raise osv.except_osv(_('Error !!'), _("%s data required %s Module to be installed, Please install %s module") %(keys,module,module)) url = self.parse_valid_url(context) context.update({'url': url}) - imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", [context.get('email_user')], context) + imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", context.get('email_user'), context) imp.set_table_list(keys) imp.start() obj_model = self.pool.get('ir.model.data') diff --git a/addons/import_sugarcrm/sugar.py b/addons/import_sugarcrm/sugar.py index 783878723e9..4ce5e0048ea 100644 --- a/addons/import_sugarcrm/sugar.py +++ b/addons/import_sugarcrm/sugar.py @@ -32,13 +32,21 @@ import import_sugarcrm import logging +import sys + + +debug = False + class LoginError(Exception): pass def login(username, password, url): setURL(url) loc = sugarsoapLocator() - portType = loc.getsugarsoapPortType(url) + if debug: + portType = loc.getsugarsoapPortType(url, tracefile=sys.stdout) + else: + portType = loc.getsugarsoapPortType(url) request = loginRequest() uauth = ns0.user_auth_Def(request) request._user_auth = uauth