Merge lp:~renatonlima/openerp-fiscal-rules/account_fiscal_position_rule_sale into lp:openerp-fiscal-rules

Proposed by Renato Lima - http://www.akretion.com
Status: Merged
Merged at revision: 59
Proposed branch: lp:~renatonlima/openerp-fiscal-rules/account_fiscal_position_rule_sale
Merge into: lp:openerp-fiscal-rules
Diff against target: 204 lines (+69/-71)
4 files modified
account_fiscal_position_rule_sale/__init__.py (+0/-2)
account_fiscal_position_rule_sale/__openerp__.py (+12/-14)
account_fiscal_position_rule_sale/sale.py (+53/-54)
account_fiscal_position_rule_sale/sale_view.xml (+4/-1)
To merge this branch: bzr merge lp:~renatonlima/openerp-fiscal-rules/account_fiscal_position_rule_sale
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, no test Approve
Review via email: mp+147676@code.launchpad.net

Description of the change

- migrated Views
- Code formatting according to PEP-8
- Refactored stock.picking methods

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

In __openerp__.py you can replace the entry points 'init_xml' and 'update_xml' by 'data'.

in __openerp__.py still, the comment:
## WHEN MERGING PLEASE LEAVE THE DEPENDENCY ON delivery BECAUSE OTHERWISE THE ONCHANGE_PARTNER_ID WILL BE TRIGGERED SOMETIMES IN DELIVERY
speak about a dependency on delivery but there is no such dependency. Comment to remove, or dependency to add?

l.81
Are you sure that the key 'context' will always be present in kwargs?
I think that you should default it to {} when the key is not found in kwargs.

review: Needs Fixing (code review, no test)
59. By Renato Lima - http://www.akretion.com

Added context default and use domain and removed comment in __openerp__.py

Revision history for this message
Renato Lima - http://www.akretion.com (renatonlima) wrote :

Hello Guewen,

I fixed conflict between account_fiscal_position_sale and delivery module, but I forgot remove comment in __openerp__.py

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Quick note on:
    if not kwargs.get('context', False):

You can just write:
    if not kwargs.get('context'):

Because {}.get() returns None when the key is not found, so it is evaluated to False.

Thanks for the changes: LGTM

review: Approve (code review, no test)
Revision history for this message
Niels Huylebroeck (red15) wrote :

Also the big scary warning about leaving the dependency on 'delivery' when it's not even there anymore is a left over that would better be deleted I think ?

Revision history for this message
Niels Huylebroeck (red15) wrote :

Nvm, was looking at mail diff which is behind on revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_fiscal_position_rule_sale/__init__.py'
2--- account_fiscal_position_rule_sale/__init__.py 2012-10-29 13:41:30 +0000
3+++ account_fiscal_position_rule_sale/__init__.py 2013-02-11 23:53:21 +0000
4@@ -20,5 +20,3 @@
5 ###############################################################################
6
7 import sale
8-
9-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
10
11=== modified file 'account_fiscal_position_rule_sale/__openerp__.py'
12--- account_fiscal_position_rule_sale/__openerp__.py 2012-12-07 21:59:45 +0000
13+++ account_fiscal_position_rule_sale/__openerp__.py 2013-02-11 23:53:21 +0000
14@@ -25,22 +25,20 @@
15 'name': 'Account Fiscal Position Rule Sale',
16 'version': '1.1',
17 'category': 'Generic Modules/Accounting',
18- 'description': """Include a rule to decide the correct fiscal position for Sale""",
19+ 'description': """Include a rule to decide the
20+ correct fiscal position for Sale""",
21 'author': 'Akretion',
22 'license': 'AGPL-3',
23 'website': 'http://www.akretion.com',
24- ## WHEN MERGING PLEASE LEAVE THE DEPENDENCY ON delivery BECAUSE OTHERWISE THE ONCHANGE_PARTNER_ID WILL BE TRIGGERED SOMETIMES IN DELIVERY
25- 'depends': ['account_fiscal_position_rule', 'sale'],
26- 'init_xml': [],
27- 'update_xml':
28- [
29- 'sale_view.xml',
30- 'security/account_fiscal_position_rule_sale_security.xml',
31- 'security/ir.model.access.csv',
32-
33- ],
34- 'demo_xml': [],
35+ 'depends': [
36+ 'account_fiscal_position_rule',
37+ 'sale',
38+ ],
39+ 'data': [
40+ 'sale_view.xml',
41+ 'security/account_fiscal_position_rule_sale_security.xml',
42+ 'security/ir.model.access.csv',
43+ ],
44+ 'demo': [],
45 'installable': True,
46 }
47-
48-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
49
50=== modified file 'account_fiscal_position_rule_sale/sale.py'
51--- account_fiscal_position_rule_sale/sale.py 2012-12-07 22:05:13 +0000
52+++ account_fiscal_position_rule_sale/sale.py 2013-02-11 23:53:21 +0000
53@@ -23,82 +23,81 @@
54 #
55 ###############################################################################
56
57-from osv import fields, osv
58+from osv import osv
59
60
61 class sale_order(osv.Model):
62- _inherit = "sale.order"
63-
64- def onchange_partner_id(self, cr, uid, ids, partner_id,
65- context=None, shop_id=False, **kwargs):
66-
67- result = super(sale_order, self).onchange_partner_id(cr, uid, ids,
68- partner_id,
69- context)
70- if not shop_id:
71- return result
72-
73- context.update({'use_domain': ('use_sale', '=', True)})
74- obj_shop = self.pool.get('sale.shop').browse(cr, uid, shop_id)
75+ _inherit = 'sale.order'
76+
77+ def _fiscal_position_map(self, cr, uid, result, **kwargs):
78+
79+ if not kwargs.get('context', False):
80+ kwargs['context'] = {}
81+
82+ kwargs['context'].update({'use_domain': ('use_sale', '=', True)})
83+ obj_shop = self.pool.get('sale.shop').browse(
84+ cr, uid, kwargs.get('shop_id'))
85 company_id = obj_shop.company_id.id
86- partner_invoice_id = result['value'].get('partner_invoice_id', False)
87- partner_shipping_id = result['value'].get('partner_shipping_id', False)
88-
89- kwargs.update({
90- 'partner_id': partner_id,
91- 'partner_invoice_id': partner_invoice_id,
92- 'partner_shipping_id': partner_shipping_id,
93- 'company_id': company_id,
94- 'context': context
95- })
96+ kwargs.update({'company_id': company_id})
97 fp_rule_obj = self.pool.get('account.fiscal.position.rule')
98 return fp_rule_obj.apply_fiscal_mapping(cr, uid, result, kwargs)
99
100+ def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
101+
102+ if not context:
103+ context = {}
104+
105+ result = super(sale_order, self).onchange_partner_id(
106+ cr, uid, ids, partner_id, context)
107+
108+ if context.get('shop_id', False):
109+ return result
110+
111+ kwargs = context.update({
112+ 'shop_id': context.get('shop_id', False),
113+ 'partner_id': partner_id,
114+ 'partner_invoice_id': result['value'].get('partner_invoice_id', False),
115+ 'partner_shipping_id': result['value'].get('partner_shipping_id', False),
116+ 'context': context
117+ })
118+ return self._fiscal_position_map(cr, uid, result, **kwargs)
119+
120 def onchange_address_id(self, cr, uid, ids, partner_invoice_id,
121 partner_shipping_id, partner_id,
122 shop_id=False, context=None, **kwargs):
123
124+ if not context:
125+ context = {}
126+
127 result = {'value': {}}
128 if not shop_id or not partner_invoice_id:
129 return result
130
131- obj_shop = self.pool.get('sale.shop').browse(cr, uid, shop_id)
132- company_id = obj_shop.company_id.id
133-
134- context.update({'use_domain': ('use_sale', '=', True)})
135 kwargs.update({
136- 'partner_id': partner_id,
137- 'partner_invoice_id': partner_invoice_id,
138- 'partner_shipping_id': partner_shipping_id,
139- 'company_id': company_id,
140- 'context': context
141- })
142- fp_rule_obj = self.pool.get('account.fiscal.position.rule')
143- return fp_rule_obj.apply_fiscal_mapping(cr, uid, result, kwargs)
144+ 'shop_id': shop_id,
145+ 'partner_id': partner_id,
146+ 'partner_invoice_id': partner_invoice_id,
147+ 'partner_shipping_id': partner_shipping_id,
148+ 'context': context
149+ })
150+ return self._fiscal_position_map(cr, uid, result, **kwargs)
151
152 def onchange_shop_id(self, cr, uid, ids, shop_id, context=None,
153 partner_id=None, partner_invoice_id=None,
154 partner_shipping_id=None, **kwargs):
155
156- result = super(sale_order, self).onchange_shop_id(cr, uid, ids,
157- shop_id, context)
158+ if not context:
159+ context = {}
160+
161+ result = {'value': {}}
162 if not shop_id or not partner_id:
163 return result
164
165- obj_shop = self.pool.get('sale.shop').browse(cr, uid, shop_id)
166- company_id = obj_shop.company_id.id
167-
168- context.update({'use_domain': ('use_sale', '=', True)})
169 kwargs.update({
170- 'partner_id': partner_id,
171- 'partner_invoice_id': partner_invoice_id,
172- 'partner_shipping_id': partner_shipping_id,
173- 'company_id': company_id,
174- 'context': context
175- })
176- fp_rule_obj = self.pool.get('account.fiscal.position.rule')
177- return fp_rule_obj.apply_fiscal_mapping(cr, uid, result, kwargs)
178-
179-sale_order()
180-
181-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
182+ 'shop_id': shop_id,
183+ 'partner_id': partner_id,
184+ 'partner_invoice_id': partner_invoice_id,
185+ 'partner_shipping_id': partner_shipping_id,
186+ 'context': context
187+ })
188+ return self._fiscal_position_map(cr, uid, result, **kwargs)
189
190=== modified file 'account_fiscal_position_rule_sale/sale_view.xml'
191--- account_fiscal_position_rule_sale/sale_view.xml 2012-12-07 21:59:45 +0000
192+++ account_fiscal_position_rule_sale/sale_view.xml 2013-02-11 23:53:21 +0000
193@@ -25,7 +25,10 @@
194 </field>
195 <field name="partner_id" position="attributes">
196 <attribute name="on_change">
197- onchange_partner_id(partner_id, context, shop_id)
198+ onchange_partner_id(partner_id, context)
199+ </attribute>
200+ <attribute name="context">
201+ {'shop_id': shop_id}
202 </attribute>
203 </field>
204 </field>