Skip to content

Commit

Permalink
FIX unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Aug 23, 2017
1 parent 4fb2236 commit b4be493
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 80 deletions.
74 changes: 71 additions & 3 deletions sale_line_option/README.rst
@@ -1,18 +1,30 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

Sale Option
==============
================
Sale Line Option
================

This module provide an options system for sale order line.


Configuration
=============

To configure this module, you need to:

* set bill of material for products which have options

.. figure:: static/description/bom.png
:alt: Bom settings
:width: 800 px


.. figure:: sale_line_option/static/description/bom.png
:alt: Bom settings
:width: 800 px

Usage
=====

Expand All @@ -21,12 +33,68 @@ To use this module, you need to:
* add a sale order line in a sale order
* choose an option

.. figure:: static/description/sale_line.png
:alt: Sale line with options: no default option when Default Quantity is 0
:width: 800 px

.. figure:: sale_line_option/static/description/sale_line.png
:alt: Sale line with options: no default option when Default Quantity is 0
:width: 800 px


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/167/8.0


Known issues / Roadmap
======================

* ...

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/167/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Valentin Chemiere <valentin.chemiere@akretion.com>
* David Béal <valentin.chemiere@akretion.com>


Do not contact contributors directly about support or help with technical issues.

Funders
-------

The development of this module has been financially supported by:

* Akretion

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
1 change: 1 addition & 0 deletions sale_line_option/__manifest__.py
Expand Up @@ -17,6 +17,7 @@
'views/sale_view.xml',
'views/mrp_view.xml',
'views/install.xml',
'data/bom_option.xml',
'security/ir.model.access.csv',
],
'demo': [
Expand Down
14 changes: 14 additions & 0 deletions sale_line_option/data/bom_option.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="option_type_select" model="mrp.bom.line.option">
<field name="name">Selection</field>
<field name="type">select</field>
</record>
<record id="option_type_required" model="mrp.bom.line.option">
<field name="name">Required</field>
<field name="type">required</field>
</record>


</odoo>
21 changes: 8 additions & 13 deletions sale_line_option/demo/product_demo.xml
Expand Up @@ -13,11 +13,6 @@
<field name="name">Config with opts3</field>
<field name="default_code">CFG3</field>
</record>
<record id="option_type" model="mrp.bom.line.option">
<field name="name">Test</field>
<field name="type">select</field>
</record>


<record id="bom_pc_assmb_option1" model="mrp.bom">
<field name="product_tmpl_id"
Expand All @@ -28,24 +23,24 @@
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option1"/>
<field name="product_id" ref="product.product_product_20"/>
<field name="default_qty">1</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>
<record id="bom_line_pc_assmb_option12" model="mrp.bom.line">
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option1"/>
<field name="product_id" ref="product.product_product_12"/>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>
<record id="bom_line_pc_assmb_option13" model="mrp.bom.line">
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option1"/>
<field name="product_id" ref="product.product_product_13"/>
<field name="default_qty">2</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>
<record id="bom_line_pc_assmb_option14" model="mrp.bom.line">
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option1"/>
<field name="product_id" ref="product.product_product_10"/>
<field name="default_qty">1</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>

<record id="bom_pc_assmb_option2" model="mrp.bom">
Expand All @@ -56,13 +51,13 @@
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option2"/>
<field name="product_id" ref="product.product_product_17"/>
<field name="default_qty">2</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>
<record id="bom_line_pc_assmb_option22" model="mrp.bom.line">
<field name="bom_id" ref="sale_line_option.bom_pc_assmb_option2"/>
<field name="product_id" ref="product.product_product_13"/>
<field name="default_qty">4</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>

<record id="bom_assmb_option3" model="mrp.bom">
Expand All @@ -73,13 +68,13 @@
<field name="bom_id" ref="sale_line_option.bom_assmb_option3"/>
<field name="product_id" ref="stock.product_icecream"/>
<field name="default_qty">2</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>
<record id="bom_line_assmb_option32" model="mrp.bom.line">
<field name="bom_id" ref="sale_line_option.bom_assmb_option3"/>
<field name="product_id" ref="product.product_product_24"/>
<field name="default_qty">1</field>
<field name="option_id" ref="sale_line_option.option_type"/>
<field name="option_id" ref="sale_line_option.option_type_select"/>
</record>

<record id="sale_order_option" model="sale.order">
Expand Down
1 change: 1 addition & 0 deletions sale_line_option/models/__init__.py
@@ -1,2 +1,3 @@
from . import sale
from . import mrp
from . import stock
13 changes: 2 additions & 11 deletions sale_line_option/models/mrp.py
Expand Up @@ -11,8 +11,8 @@ class MrpBomLineOption(models.Model):
@api.model
def _get_type(self):
selection = (
('select', 'selection'),
('multiselect', 'multi-selection'),
('select', 'Selection'),
('multiselect', 'Multi-selection'),
('required', 'Required'),
)
return selection
Expand Down Expand Up @@ -90,12 +90,3 @@ def _prepare_conssumed_line(self, bom_line, quantity, product_uos_qty):
if option.bom_line_id == bom_line:
vals['product_qty'] = vals['product_qty'] * option.qty
return vals


class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'

option_ids = fields.Many2many(
comodel_name='sale.order.line.option',
relation='option_lot_rel', column1='lot_id', column2='option_id',
string='Option lines')
7 changes: 4 additions & 3 deletions sale_line_option/models/sale.py
Expand Up @@ -31,9 +31,10 @@ def create(self, vals):
def product_id_change(self):
res = super(SaleOrderLine, self).product_id_change()
if self.product_id:
implieds = self._set_product(self.product_id, self.price_unit)
for field in implieds:
self[field] = implieds[field]
self.option_ids = False
values = self._set_product(self.product_id, self.price_unit)
for field in values:
self[field] = values[field]
return res

@api.model
Expand Down
14 changes: 14 additions & 0 deletions sale_line_option/models/stock.py
@@ -0,0 +1,14 @@
# coding: utf-8
# © 2015 Akretion, Valentin CHEMIERE <valentin.chemiere@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import fields, models


class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'

option_ids = fields.Many2many(
comodel_name='sale.order.line.option',
relation='option_lot_rel', column1='lot_id', column2='option_id',
string='Option lines')
Binary file added sale_line_option/static/description/bom.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 35 additions & 28 deletions sale_line_option/tests/test_change_option.py
Expand Up @@ -12,38 +12,45 @@ class TestOptionCase(TransactionCase):

def test_sale_line_change(self):
"Check if all required options are refresh when we change the product"
# sale = self.sale_line.order_id
# sol = self.sale_line
# We have 3 options
self.assertTrue(len(self.sale_line.option_ids) == 3,
"options number is wrong in %s %s" % (
self.sale_line, self.sale_line.order_id.name))
new_product = self.env.ref('sale_line_option.product_pc_assmb_option2')
self.sale_line.product_id = new_product.id
res_onchange_product = self.sale_line.product_id_change()
import pdb; pdb.set_trace()
bom_opt2 = self.env.ref('sale_line_option.bom_pc_assmb_option2')
bom_products = [x.product_id.id
for x in bom_opt2.bom_line_ids
self.sale_line.product_id_change()
# we now have only 2 options
self.assertTrue(len(self.sale_line.option_ids) == 2,
"options number is wrong in %s %s" % (
self.sale_line, self.sale_line.order_id.name))
option_products = [x.product_id for x in self.sale_line.option_ids]
_logger.debug(' >>> Options product ids: %s',
[x.name for x in option_products])
bom_opt = self.env.ref('sale_line_option.bom_pc_assmb_option2')
bom_products = [x.product_id
for x in bom_opt.bom_line_ids
if x.default_qty > 0]
_logger.debug(' >>> Bom product ids: %s', bom_products)
onchange_value = res_onchange_product['value'].get(
'option_ids')
self.assertTrue(len(onchange_value) > 0)
opt_products = [x[2]['product_id'] for x in onchange_value]
_logger.debug(' >>> Options product ids: %s', opt_products)
self.assertTrue(len(bom_products) > 0)
self.assertTrue(len(opt_products) > 0)
if bom_products and opt_products:
self.assertEqual(set(bom_products), set(opt_products))
_logger.debug(' >>> Bom product ids: %s',
[x.name for x in bom_products])
self.assertTrue(len(bom_products) > 0,
"%s bom shouldn't be null" % bom_products)
if bom_products and option_products:
self.assertEqual(set(bom_products), set(option_products),
"Bom and option products should be identical")

# def test_check_option_line_when_bom_change(self):
# "Check if remove bom.line have no impact on option lines"
# bom_line = self.env.ref('sale_line_option.bom_line_pc_assmb_option13')
# # import pdb; pdb.set_trace()
# product = bom_line.product_id
# bom_line.unlink()
# option = [x for x in self.sale_line.option_ids
# if x.product_id == product]
# self.assertTrue(len(option) == 1)
# if option:
# self.assertTrue(len(option[0].bom_line_id) == 0)
def test_check_option_line_when_bom_change(self):
"Check if remove bom.line have no impact on option lines"
bom_line = self.env.ref('sale_line_option.bom_line_pc_assmb_option13')
product = bom_line.product_id
bom_line.unlink()
option = [x for x in self.sale_line.option_ids
if x.product_id == product]
self.assertTrue(len(option) == 1,
"We should have 1 option %s" % option)
if option:
self.assertTrue(len(option[0].bom_line_id) == 0,
"Option bom_line %s should be null"
% option[0].bom_line_id)

def setUp(self):
super(TestOptionCase, self).setUp()
Expand Down
22 changes: 0 additions & 22 deletions sale_line_option/views/sale_view.xml
Expand Up @@ -38,28 +38,6 @@
</field>
</record>

<!-- <record id="view_order_line_form2" model="ir.ui.view">
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_form2"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='name']" position="before">
<field name="display_option" invisible="1"/>
<label for="option_ids" attrs="{'invisible': [('display_option', '=', False)]}"/>
<field name="option_ids" context="{'line_product_id': product_id}"
attrs="{'invisible': [('display_option', '=', False)]}">
<tree editable="bottom">
<field name="bom_line_id" invisible="1"/>
<field name="product_ids" invisible="1"/>
<field name="product_id"
domain="[('id', 'in', product_ids[0][2]')]"/>
<field name="qty"/>
<field name="line_price"/>
</tree>
</field>
</xpath>
</field>
</record>

-->
</data>
</openerp>

0 comments on commit b4be493

Please sign in to comment.