Merge lp:~agilebg/sale-wkfl/adding_product_customer_code_sale_7 into lp:~sale-core-editors/sale-wkfl/7.0

Proposed by Nicola Malcontenti - Agile BG
Status: Merged
Merged at revision: 43
Proposed branch: lp:~agilebg/sale-wkfl/adding_product_customer_code_sale_7
Merge into: lp:~sale-core-editors/sale-wkfl/7.0
Diff against target: 232 lines (+201/-0)
6 files modified
product_customer_code_sale/__init__.py (+21/-0)
product_customer_code_sale/__openerp__.py (+44/-0)
product_customer_code_sale/i18n/it.po (+28/-0)
product_customer_code_sale/i18n/product_customer_code_sale.pot (+27/-0)
product_customer_code_sale/sale.py (+54/-0)
product_customer_code_sale/sale_view.xml (+27/-0)
To merge this branch: bzr merge lp:~agilebg/sale-wkfl/adding_product_customer_code_sale_7
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Lorenzo Battistini (community) code review Approve
Review via email: mp+202468@code.launchpad.net

Description of the change

Based on product_customer_code, this module loads in every sale order line the customer code defined in the product.
This module depends on https://code.launchpad.net/~akretion-team/openerp-product-attributes/7.0-product-customer-code-extraction/+merge/198296.

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

Thanks

Notes (but I won't block the MP for that):

You don't need to do

    176 + if context is None:
    177 + context = {}

When the context is not accessed within the method.

You should prefer self.pool['product.customer.code'] over self.pool.get('product.customer.code') because it the model is missing for some reason, it will fail directly with a KeyError rather than some lines below with a more obscure error (AttributeError: 'NoneType' object has no attribute 'browse')

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'product_customer_code_sale'
2=== added file 'product_customer_code_sale/__init__.py'
3--- product_customer_code_sale/__init__.py 1970-01-01 00:00:00 +0000
4+++ product_customer_code_sale/__init__.py 2014-01-21 14:40:39 +0000
5@@ -0,0 +1,21 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
10+# Author: Nicola Malcontenti <nicola.malcontenti@agilebg.com>
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as published
14+# by the Free Software Foundation, either version 3 of the License, or
15+# (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+from . import sale
27
28=== added file 'product_customer_code_sale/__openerp__.py'
29--- product_customer_code_sale/__openerp__.py 1970-01-01 00:00:00 +0000
30+++ product_customer_code_sale/__openerp__.py 2014-01-21 14:40:39 +0000
31@@ -0,0 +1,44 @@
32+# -*- coding: utf-8 -*-
33+##############################################################################
34+#
35+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
36+# Author: Nicola Malcontenti <nicola.malcontenti@agilebg.com>
37+#
38+# This program is free software: you can redistribute it and/or modify
39+# it under the terms of the GNU Affero General Public License as published
40+# by the Free Software Foundation, either version 3 of the License, or
41+# (at your option) any later version.
42+#
43+# This program is distributed in the hope that it will be useful,
44+# but WITHOUT ANY WARRANTY; without even the implied warranty of
45+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46+# GNU Affero General Public License for more details.
47+#
48+# You should have received a copy of the GNU Affero General Public License
49+# along with this program. If not, see <http://www.gnu.org/licenses/>.
50+#
51+##############################################################################
52+{
53+ "name" : "Product Customer code on sale",
54+ "version" : "1.0",
55+ "author" : "Agile Business Group",
56+ "website" : "http://www.agilebg.com",
57+ "category" : "Sales Management",
58+ "depends" : [
59+ 'base',
60+ 'product',
61+ 'sale',
62+ 'product_customer_code'
63+ ],
64+ "description": """
65+ Based on product_customer_code,
66+ this module loads in every sale order line
67+ the customer code defined in the product,
68+ """,
69+ "demo" : [],
70+ "data" : [
71+ 'sale_view.xml',
72+ ],
73+ 'installable' : True,
74+ 'active' : False,
75+}
76
77=== added directory 'product_customer_code_sale/i18n'
78=== added file 'product_customer_code_sale/i18n/it.po'
79--- product_customer_code_sale/i18n/it.po 1970-01-01 00:00:00 +0000
80+++ product_customer_code_sale/i18n/it.po 2014-01-21 14:40:39 +0000
81@@ -0,0 +1,28 @@
82+# Translation of OpenERP Server.
83+# This file contains the translation of the following modules:
84+# * product_customer_code_sale
85+#
86+msgid ""
87+msgstr ""
88+"Project-Id-Version: OpenERP Server 7.0\n"
89+"Report-Msgid-Bugs-To: \n"
90+"POT-Creation-Date: 2014-01-15 14:30+0000\n"
91+"PO-Revision-Date: 2014-01-15 15:49+0100\n"
92+"Last-Translator: <>\n"
93+"Language-Team: \n"
94+"MIME-Version: 1.0\n"
95+"Content-Type: text/plain; charset=UTF-8\n"
96+"Content-Transfer-Encoding: 8bit\n"
97+"Plural-Forms: \n"
98+"Language: it\n"
99+"X-Generator: Poedit 1.6.2\n"
100+
101+#. module: product_customer_code_sale
102+#: field:sale.order.line,product_customer_code:0
103+msgid "Product Customer Code"
104+msgstr "Codice Prodotto Cliente"
105+
106+#. module: product_customer_code_sale
107+#: model:ir.model,name:product_customer_code_sale.model_sale_order_line
108+msgid "Sales Order Line"
109+msgstr "Linea d'ordine di vendita"
110
111=== added file 'product_customer_code_sale/i18n/product_customer_code_sale.pot'
112--- product_customer_code_sale/i18n/product_customer_code_sale.pot 1970-01-01 00:00:00 +0000
113+++ product_customer_code_sale/i18n/product_customer_code_sale.pot 2014-01-21 14:40:39 +0000
114@@ -0,0 +1,27 @@
115+# Translation of OpenERP Server.
116+# This file contains the translation of the following modules:
117+# * product_customer_code_sale
118+#
119+msgid ""
120+msgstr ""
121+"Project-Id-Version: OpenERP Server 7.0\n"
122+"Report-Msgid-Bugs-To: \n"
123+"POT-Creation-Date: 2014-01-15 14:31+0000\n"
124+"PO-Revision-Date: 2014-01-15 14:31+0000\n"
125+"Last-Translator: <>\n"
126+"Language-Team: \n"
127+"MIME-Version: 1.0\n"
128+"Content-Type: text/plain; charset=UTF-8\n"
129+"Content-Transfer-Encoding: \n"
130+"Plural-Forms: \n"
131+
132+#. module: product_customer_code_sale
133+#: field:sale.order.line,product_customer_code:0
134+msgid "Product Customer Code"
135+msgstr ""
136+
137+#. module: product_customer_code_sale
138+#: model:ir.model,name:product_customer_code_sale.model_sale_order_line
139+msgid "Sales Order Line"
140+msgstr ""
141+
142
143=== added file 'product_customer_code_sale/sale.py'
144--- product_customer_code_sale/sale.py 1970-01-01 00:00:00 +0000
145+++ product_customer_code_sale/sale.py 2014-01-21 14:40:39 +0000
146@@ -0,0 +1,54 @@
147+# -*- coding: utf-8 -*-
148+##############################################################################
149+#
150+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
151+# Author: Nicola Malcontenti <nicola.malcontenti@agilebg.com>
152+#
153+# This program is free software: you can redistribute it and/or modify
154+# it under the terms of the GNU Affero General Public License as published
155+# by the Free Software Foundation, either version 3 of the License, or
156+# (at your option) any later version.
157+#
158+# This program is distributed in the hope that it will be useful,
159+# but WITHOUT ANY WARRANTY; without even the implied warranty of
160+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+# GNU Affero General Public License for more details.
162+#
163+# You should have received a copy of the GNU Affero General Public License
164+# along with this program. If not, see <http://www.gnu.org/licenses/>.
165+#
166+##############################################################################
167+from openerp.osv import fields, orm
168+
169+
170+class sale_order_line(orm.Model):
171+ _inherit = 'sale.order.line'
172+
173+ def _get_product_customer_code(
174+ self, cr, uid, ids,
175+ name, args, context=None):
176+ if context is None:
177+ context = {}
178+ res = {}
179+ product_customer_code_obj = self.pool.get('product.customer.code')
180+ for line in self.browse(cr, uid, ids, context=context):
181+ res[line.id] = ''
182+ partner = line.order_id.partner_id
183+ product = line.product_id
184+ if product and partner:
185+ code_ids = product_customer_code_obj.search(cr, uid, [
186+ ('product_id', '=', product.id),
187+ ('partner_id', '=', partner.id),
188+ ], limit=1, context=context)
189+ if code_ids:
190+ code = product_customer_code_obj.browse(
191+ cr, uid,
192+ code_ids[0], context=context).product_code or ''
193+ res[line.id] = code
194+ return res
195+
196+ _columns = {
197+ 'product_customer_code': fields.function(
198+ _get_product_customer_code,
199+ string='Product Customer Code', type='char', size=64),
200+ }
201
202=== added file 'product_customer_code_sale/sale_view.xml'
203--- product_customer_code_sale/sale_view.xml 1970-01-01 00:00:00 +0000
204+++ product_customer_code_sale/sale_view.xml 2014-01-21 14:40:39 +0000
205@@ -0,0 +1,27 @@
206+<?xml version="1.0" encoding="utf-8"?>
207+<!--
208+ product customer code for OpenERP
209+ Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>).
210+ Authors, Nicola Malcontenti, nicola.malcontenti@agilebg.com
211+ The licence is in the file __openerp__.py
212+-->
213+<openerp>
214+ <data>
215+
216+ <record id="view_order_form" model="ir.ui.view">
217+ <field name="name">sale.order.product.code.view.form</field>
218+ <field name="model">sale.order</field>
219+ <field name="inherit_id" ref="sale.view_order_form"/>
220+ <field eval="16" name="priority"/>
221+ <field name="arch" type="xml">
222+ <xpath expr="//form//tree//field[@name='product_id']" position="after">
223+ <field name="product_customer_code"/>
224+ </xpath>
225+ <xpath expr="//form//form//field[@name='product_id']" position="after">
226+ <field name="product_customer_code"/>
227+ </xpath>
228+ </field>
229+ </record>
230+
231+ </data>
232+</openerp>

Subscribers

People subscribed via source and target branches