Merge lp:~initos.com/account-invoice-report/7.0-fix_lang_for_draft into lp:~account-core-editors/account-invoice-report/7.0

Proposed by Katja Matthes
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 62
Merged at revision: 63
Proposed branch: lp:~initos.com/account-invoice-report/7.0-fix_lang_for_draft
Merge into: lp:~account-core-editors/account-invoice-report/7.0
Diff against target: 59 lines (+12/-11)
2 files modified
invoice_webkit/invoice.py (+10/-9)
invoice_webkit/view/invoice_view.xml (+2/-2)
To merge this branch: bzr merge lp:~initos.com/account-invoice-report/7.0-fix_lang_for_draft
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no test Approve
Markus Schneider (community) review & testing Approve
Pedro Manuel Baeza code review Needs Fixing
Review via email: mp+224109@code.launchpad.net

Description of the change

Steps to reproduce:
1) In invoice tree view klick 'Create' to open draft formular for a new invoice
2) Choose for partner_id a partner with an other language than English
3) Set text_condition{1,2}

Result
English version of condition text is set to note{1,2}.

Expected Result:
Use language of set partner while setting note{1,2}.

Solution:
Add partner_id as parameter to on_change function for text_condition{1,2}

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Katja,

You're right that current code doesn't work, but this is because the line that made the work is incorrect:

try :
    lang = self.browse(cr, uid, inv_id).partner_id.lang

inv_id is an id, not a list of ids, so you don't need to put index 0 to access browse_record.

I think it's better to simply fix this instead of changing all the code you put.

Regards.

review: Needs Fixing (code review)
Revision history for this message
Katja Matthes (katja-matthes) wrote :

Hi Pedro,

thanks for reviewing.

Well I debug this and actually inv_id is a list. It would be better to rename it to inv_ids. I can add this, if it's wished.

I think you don't understand the issue in detail. The problem occure, when creating an invoice. At this point there's no invoice id, cause the object isn't stored yet. To get the customer's language at this point the only solution I see is to modify the on_change method like the way I did.

If I'm missing something fundamental, please let me know.

Greetings,
Katja

Revision history for this message
Markus Schneider (markus-schneider) wrote :

solve the problem with multi language installation

review: Approve (review & testing)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

review: Approve (code review, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the fix.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'invoice_webkit/invoice.py'
2--- invoice_webkit/invoice.py 2013-02-01 08:46:04 +0000
3+++ invoice_webkit/invoice.py 2014-06-23 11:29:29 +0000
4@@ -18,6 +18,8 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6 ##############################################################################
7 from openerp.osv.orm import Model, fields
8+from openerp.osv import osv
9+from openerp.tools.translate import _
10
11
12 class InvoiceConditionText(Model):
13@@ -38,22 +40,21 @@
14
15 _inherit = "account.invoice"
16
17- def _set_condition(self, cr, uid, inv_id, commentid, key):
18+ def _set_condition(self, cr, uid, inv_id, commentid, key, partner_id=False):
19 """Set the text of the notes in invoices"""
20 if not commentid:
21 return {}
22- try :
23- lang = self.browse(cr, uid, inv_id)[0].partner_id.lang
24- except :
25- lang = 'en_US'
26+ if not partner_id:
27+ raise osv.except_osv(_('No Customer Defined !'), _('Before choosing condition text select a customer.'))
28+ lang = self.pool.get('res.partner').browse(cr, uid, partner_id).lang or 'en_US'
29 cond = self.pool.get('account.condition_text').browse(cr, uid, commentid, {'lang': lang})
30 return {'value': {key: cond.text}}
31
32- def set_header(self, cr, uid, inv_id, commentid):
33- return self._set_condition(cr, uid, inv_id, commentid, 'note1')
34+ def set_header(self, cursor, uid, inv_id, commentid, partner_id=False):
35+ return self._set_condition(cursor, uid, inv_id, commentid, 'note1', partner_id)
36
37- def set_footer(self, cr, uid, inv_id, commentid):
38- return self._set_condition(cr, uid, inv_id, commentid, 'note2')
39+ def set_footer(self, cursor, uid, inv_id, commentid, partner_id=False):
40+ return self._set_condition(cursor, uid, inv_id, commentid, 'note2', partner_id)
41
42 _columns = {'text_condition1': fields.many2one('account.condition_text', 'Header condition',
43 domain=[('type', '=', 'header')]),
44
45=== modified file 'invoice_webkit/view/invoice_view.xml'
46--- invoice_webkit/view/invoice_view.xml 2013-03-04 06:52:00 +0000
47+++ invoice_webkit/view/invoice_view.xml 2014-06-23 11:29:29 +0000
48@@ -53,9 +53,9 @@
49 <page string="Conditions">
50 <group>
51 <field name="text_condition1" domain="[('type','=','header')]"
52- on_change="set_header(text_condition1)" colspan="2"/>
53+ on_change="set_header(text_condition1, partner_id)" colspan="2"/>
54 <field name="text_condition2" domain="[('type','=','footer')]"
55- on_change="set_footer(text_condition2)" colspan="2"/>
56+ on_change="set_footer(text_condition2, partner_id)" colspan="2"/>
57 <field name="note1" colspan="4" nolabel="1" placeholder="Your top conditions here"/>
58 <field name="note2" colspan="4" nolabel="1" placeholder="Your bottom conditions here"/>
59 </group>

Subscribers

People subscribed via source and target branches