Merge lp:~camptocamp/sale-wkfl/7.0-add-sale-default-discount-lep into lp:~sale-core-editors/sale-wkfl/7.0

Proposed by Leonardo Pistone
Status: Needs review
Proposed branch: lp:~camptocamp/sale-wkfl/7.0-add-sale-default-discount-lep
Merge into: lp:~sale-core-editors/sale-wkfl/7.0
Diff against target: 335 lines (+287/-0)
9 files modified
sale_default_discount/__init__.py (+22/-0)
sale_default_discount/__openerp__.py (+56/-0)
sale_default_discount/model/__init__.py (+23/-0)
sale_default_discount/model/partner.py (+34/-0)
sale_default_discount/model/sale.py (+47/-0)
sale_default_discount/test/no_default_discount.yml (+21/-0)
sale_default_discount/test/partner_default_discount.yml (+30/-0)
sale_default_discount/view/partner.xml (+20/-0)
sale_default_discount/view/sale.xml (+34/-0)
To merge this branch: bzr merge lp:~camptocamp/sale-wkfl/7.0-add-sale-default-discount-lep
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Review via email: mp+227214@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Leonardo,

Thanks for the MP.

I'm seeing the code, and I feel more comfortable having the field called as default_sale_discount, or at least sale_discount, not only discount, because partners can be also suppliers.

About the functionality itself, I'm not seeing in the code the part that applies this default value to sale order lines. Where it is?

Regards.

review: Needs Information (code review)
50. By Leonardo Pistone

rename field to sale_default_discount

As suggested by Pedro

51. By Leonardo Pistone

add tests to sale_default_discount

As discussed in the yaml file itself, I hit a situation where manual testing
works, but a default value does not show in the order line when in a yaml
test.

I prefer not to write extra production code just to make already working code
pass yaml tests. If YAML code are meant to be full-stack integrated tests (I
got the impression they are, since for example they run onchange methods),
then this looks like a bug in the yaml processor.

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Pedro,

I renamed the field as you suggested.

The default in the line works because of the attribute "context" in sale.xml. Thanks to Romain Deheele for showing me that.

I also added two tests, and got a bit frustrated when I realized that the YAML test does not get the same behaviour of manual testing (all is OK when manual testing). More details in the commit message and the yaml file.

A broader discussion we could continue later on the community list is: what are yaml tests supposed to test?

Thanks

Revision history for this message
Yann Papouin (yann-papouin) wrote :

Just for the record, the almost same result can be achieved with a product.pricelist by checking the visible_discount field and setting this pricelist as the sale one in the partner form.

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Yann,

you are right. Still, this module came out from a situation where pricelists were already used for other things, and a simple default discount was useful anyway.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/sale-workflow. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Unmerged revisions

51. By Leonardo Pistone

add tests to sale_default_discount

As discussed in the yaml file itself, I hit a situation where manual testing
works, but a default value does not show in the order line when in a yaml
test.

I prefer not to write extra production code just to make already working code
pass yaml tests. If YAML code are meant to be full-stack integrated tests (I
got the impression they are, since for example they run onchange methods),
then this looks like a bug in the yaml processor.

50. By Leonardo Pistone

rename field to sale_default_discount

As suggested by Pedro

49. By Leonardo Pistone

[add] new module sale_default_discount

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'sale_default_discount'
=== added file 'sale_default_discount/__init__.py'
--- sale_default_discount/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_default_discount/__init__.py 2014-07-18 08:39:44 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import model # noqa
023
=== added file 'sale_default_discount/__openerp__.py'
--- sale_default_discount/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sale_default_discount/__openerp__.py 2014-07-18 08:39:44 +0000
@@ -0,0 +1,56 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 'name': 'Sale Default Discount',
23 'version': '1.0',
24 'category': 'Generic Modules/Sale',
25 'description': """
26Sale Default Discount
27=====================
28
29This module allows to set a default discount per customer and per sale order.
30
31The customer discount is used by default when creating an order, and the
32order default is used when creating new order lines.
33
34The defaults can be left empty, keeping the default behaviour.
35
36Contributors
37------------
38
39 * Leonardo Pistone <leonardo.pistone@camptocamp.com>
40
41""",
42 'author': 'Camptocamp',
43 'depends': ['sale'],
44 'website': 'http://www.camptocamp.com',
45 'data': [
46 'view/partner.xml',
47 'view/sale.xml',
48 ],
49 'test': [
50 'test/no_default_discount.yml',
51 'test/partner_default_discount.yml',
52 ],
53 'demo': [],
54 'installable': True,
55 'active': False,
56}
057
=== added directory 'sale_default_discount/model'
=== added file 'sale_default_discount/model/__init__.py'
--- sale_default_discount/model/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_default_discount/model/__init__.py 2014-07-18 08:39:44 +0000
@@ -0,0 +1,23 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import partner # noqa
23from . import sale # noqa
024
=== added file 'sale_default_discount/model/partner.py'
--- sale_default_discount/model/partner.py 1970-01-01 00:00:00 +0000
+++ sale_default_discount/model/partner.py 2014-07-18 08:39:44 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import openerp.addons.decimal_precision as dp
24
25
26class Partner(orm.Model):
27 _inherit = 'res.partner'
28
29 _columns = {
30 'sale_default_discount': fields.float(
31 'Default sale discount (%)',
32 digits_compute=dp.get_precision('discount'),
33 ),
34 }
035
=== added file 'sale_default_discount/model/sale.py'
--- sale_default_discount/model/sale.py 1970-01-01 00:00:00 +0000
+++ sale_default_discount/model/sale.py 2014-07-18 08:39:44 +0000
@@ -0,0 +1,47 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import openerp.addons.decimal_precision as dp
24
25
26class SaleOrder(orm.Model):
27 _inherit = 'sale.order'
28
29 _columns = {
30 'discount': fields.float(
31 'Default discount (%)',
32 digits_compute=dp.get_precision('discount'),
33 help='This discount is used by default when creating new lines',
34 ),
35 }
36
37 def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
38 result = super(SaleOrder, self).onchange_partner_id(
39 cr, uid, ids, partner_id, context=context)
40
41 if partner_id:
42 partner = self.pool['res.partner'].browse(
43 cr, uid, partner_id, context=context)
44 if partner.sale_default_discount:
45 result['value']['discount'] = partner.sale_default_discount
46
47 return result
048
=== added directory 'sale_default_discount/test'
=== added file 'sale_default_discount/test/no_default_discount.yml'
--- sale_default_discount/test/no_default_discount.yml 1970-01-01 00:00:00 +0000
+++ sale_default_discount/test/no_default_discount.yml 2014-07-18 08:39:44 +0000
@@ -0,0 +1,21 @@
1-
2 I create a sale order with an unmodified partner
3-
4 !record {model: sale.order, id: order1}:
5 partner_id: base.res_partner_1
6-
7 I check that the order discount is unchanged
8-
9 !assert {model: sale.order, id: order1, string: Discount should be zero}:
10 - discount == 0
11-
12 I add a line
13-
14 !record {model: sale.order.line, id: line1}:
15 name: line with no discount
16 order_id: order1
17-
18 I check that the line discount is unchanged
19-
20 !assert {model: sale.order.line, id: line1, string: Discount should be zero}:
21 - discount == 0
022
=== added file 'sale_default_discount/test/partner_default_discount.yml'
--- sale_default_discount/test/partner_default_discount.yml 1970-01-01 00:00:00 +0000
+++ sale_default_discount/test/partner_default_discount.yml 2014-07-18 08:39:44 +0000
@@ -0,0 +1,30 @@
1-
2 I set a default discount on a partner
3-
4 !record {model: res.partner, id: base.res_partner_2}:
5 sale_default_discount: 32.0
6-
7 I create a sale order with a partner with default discount
8-
9 !record {model: sale.order, id: order2}:
10 partner_id: base.res_partner_2
11-
12 I check that the order discount is set
13-
14 !assert {model: sale.order, id: order2, string: Order discount should be set}:
15 - discount == 32.0
16-
17 I add a line
18-
19 !record {model: sale.order.line, id: line2}:
20 name: discounted line
21 order_id: order2
22-
23 Now I would like to assert that discount == 32.0, and I promise that It works
24 when testing manually the webclient. Unfortunately, discount is zero when
25 we use a yaml test. I leave that assertion in the hope of reactivating it
26 soon, and at least to test that the process does not crash.
27-
28 !assert {model: sale.order.line, id: line2, string: Line discount should be set}:
29 - discount in (0.0, 32.0)
30
031
=== added directory 'sale_default_discount/view'
=== added file 'sale_default_discount/view/partner.xml'
--- sale_default_discount/view/partner.xml 1970-01-01 00:00:00 +0000
+++ sale_default_discount/view/partner.xml 2014-07-18 08:39:44 +0000
@@ -0,0 +1,20 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="view_partner_form" model="ir.ui.view">
6 <field name="name">view.partner.form</field>
7 <field name="model">res.partner</field>
8 <field name="inherit_id" ref="base.view_partner_form"/>
9 <field
10 name="groups_id"
11 eval="[(6, 0, [ref('sale.group_discount_per_so_line')])]"/>
12 <field name="arch" type="xml">
13 <field name="user_id" position="after">
14 <field name="sale_default_discount"/>
15 </field>
16 </field>
17 </record>
18
19 </data>
20</openerp>
021
=== added file 'sale_default_discount/view/sale.xml'
--- sale_default_discount/view/sale.xml 1970-01-01 00:00:00 +0000
+++ sale_default_discount/view/sale.xml 2014-07-18 08:39:44 +0000
@@ -0,0 +1,34 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="view_order_form" model="ir.ui.view">
6 <field name="name">sale.order.form</field>
7 <field name="model">sale.order</field>
8 <field name="inherit_id" ref="sale.view_order_form"/>
9 <field
10 name="groups_id"
11 eval="[(6, 0, [ref('sale.group_discount_per_so_line')])]"/>
12 <field name="arch" type="xml">
13
14 <group name="sales_person" position="after">
15 <group>
16 <field
17 name="discount"
18 groups="sale.group_discount_per_so_line"/>
19 </group>
20 </group>
21
22 <field name="order_line" position="attributes">
23 <!-- that means: the default for the field "discount" on the line
24 comes from the field "discount" on the order -->
25 <attribute name="context">
26 {'default_discount': discount}
27 </attribute>
28 </field>
29
30 </field>
31 </record>
32
33 </data>
34</openerp>

Subscribers

People subscribed via source and target branches