← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~initos.com/sale-reports/7.0-fix_lang_for_draft into lp:sale-reports

 

Katja Matthes has proposed merging lp:~initos.com/sale-reports/7.0-fix_lang_for_draft into lp:sale-reports.

Requested reviews:
  Sale Core Editors (sale-core-editors)

For more details, see:
https://code.launchpad.net/~initos.com/sale-reports/7.0-fix_lang_for_draft/+merge/224106

Steps to reproduce:
1) In sale order tree view klick 'Create' to open draft formular for a new sale order
2) Choose for patner_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}
-- 
https://code.launchpad.net/~initos.com/sale-reports/7.0-fix_lang_for_draft/+merge/224106
Your team OpenERP Community Reviewer/Maintainer is subscribed to branch lp:sale-reports.
=== modified file 'sale_order_webkit/sale.py'
--- sale_order_webkit/sale.py	2013-03-14 14:14:24 +0000
+++ sale_order_webkit/sale.py	2014-06-23 11:09:44 +0000
@@ -18,8 +18,9 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
-from openerp.osv import orm, fields
+from openerp.osv import orm, fields, osv
 from openerp import netsvc
+from openerp.tools.translate import _
 
 
 class SaleConditionText(orm.Model):
@@ -48,23 +49,22 @@
                 'note1': fields.html('Header'),
                 'note2': fields.html('Footer')}
 
-    def _set_condition(self, cursor, uid, inv_id, commentid, key):
+    def _set_condition(self, cursor, uid, inv_id, commentid, key, partner_id=False):
         """Set the text of the notes in invoices"""
         if not commentid:
             return {}
-        try:
-            lang = self.browse(cursor, uid, inv_id)[0].partner_id.lang
-        except Exception as exc:
-            lang = 'en_US'
+        if not partner_id:
+            raise osv.except_osv(_('No Customer Defined !'), _('Before choosing condition text select a customer.'))
+        lang = self.pool.get('res.partner').browse(cursor, uid, partner_id).lang or 'en_US'
         cond = self.pool.get('sale.condition_text').browse(cursor, uid,
                                                            commentid, {'lang': lang})
         return {'value': {key: cond.text}}
 
-    def set_header(self, cursor, uid, inv_id, commentid):
-        return self._set_condition(cursor, uid, inv_id, commentid, 'note1')
+    def set_header(self, cursor, uid, inv_id, commentid, partner_id=False):
+        return self._set_condition(cursor, uid, inv_id, commentid, 'note1', partner_id)
 
-    def set_footer(self, cursor, uid, inv_id, commentid):
-        return self._set_condition(cursor, uid, inv_id, commentid, 'note2')
+    def set_footer(self, cursor, uid, inv_id, commentid, partner_id=False):
+        return self._set_condition(cursor, uid, inv_id, commentid, 'note2', partner_id)
 
     def print_quotation(self, cursor, uid, ids, context=None):
         '''

=== modified file 'sale_order_webkit/view/sale_view.xml'
--- sale_order_webkit/view/sale_view.xml	2013-03-12 12:33:46 +0000
+++ sale_order_webkit/view/sale_view.xml	2014-06-23 11:09:44 +0000
@@ -68,9 +68,9 @@
            <page string="Conditions">
              <group>
                <field name="text_condition1" domain="[('type','=','header')]"
-                      on_change="set_header(text_condition1)" colspan="2"/>
+                      on_change="set_header(text_condition1, partner_id)" colspan="2"/>
                <field name="text_condition2" domain="[('type','=','footer')]"
-                      on_change="set_footer(text_condition2)" colspan="2"/>
+                      on_change="set_footer(text_condition2, partner_id)" colspan="2"/>
                <field name="note1" colspan="4" nolabel="1" placeholder="Your top conditions here"/>
                <field name="note2" colspan="4" nolabel="1" placeholder="Your bottom conditions here"/>
              </group>


Follow ups