Browse Source

[PORT][REF] new api;

pull/40/head
Sylvain LE GAL 10 years ago
parent
commit
77657d9db6
  1. 28
      pos_order_pricelist_change/models/pos_order.py
  2. 157
      pos_order_pricelist_change/tests/test_pos_order_pricelist_change.py
  3. 6
      pos_order_pricelist_change/views/view.xml

28
pos_order_pricelist_change/models/pos_order.py

@ -20,27 +20,27 @@
#
##############################################################################
from openerp.osv.orm import Model
from openerp.tools.translate import _
from openerp.models import Model
from openerp import fields, api, _
class pos_order(Model):
class PosOrder(Model):
_inherit = 'pos.order'
def action_recompute_pricelist(self, cr, uid, ids, context=None):
pol_obj = self.pool.get('pos.order.line')
for po in self.browse(cr, uid, ids, context=context):
@api.multi
def action_recompute_pricelist(self):
pol_obj = self.env['pos.order.line']
for po in self:
for pol in po.lines:
res = pol_obj.onchange_product_id(
cr, uid, [pol.id], po.pricelist_id.id, pol.product_id.id,
pol.qty, po.partner_id.id)
res = pol.onchange_product_id(
po.pricelist_id.id, pol.product_id.id, qty=pol.qty,
partner_id=po.partner_id.id)
if res['value']['price_unit'] != pol.price_unit:
pol_obj.write(
cr, uid, [pol.id], res['value'], context=context)
pol.write(res['value'])
def onchange_pricelist_id(
self, cr, uid, ids, pricelist_id, lines, context=None):
if not pricelist_id or not lines:
@api.onchange('pricelist_id')
def onchange_pricelist_id(self):
if not self.pricelist_id or not self.lines:
return {}
warning = {
'title': _('Pricelist Warning!'),

157
pos_order_pricelist_change/tests/test_pos_order_pricelist_change.py

@ -28,161 +28,90 @@ class TestPosOrderPricelistChange(TransactionCase):
def setUp(self):
super(TestPosOrderPricelistChange, self).setUp()
self.imd_obj = self.registry('ir.model.data')
self.pp_obj = self.registry('product.product')
self.ppl_obj = self.registry('product.pricelist')
self.po_obj = self.registry('pos.order')
self.pol_obj = self.registry('pos.order.line')
self.pc_obj = self.registry('pos.config')
self.ps_obj = self.registry('pos.session')
self.imd_obj = self.env['ir.model.data']
self.pp_obj = self.env['product.product']
self.ppl_obj = self.env['product.pricelist']
self.po_obj = self.env['pos.order']
self.pol_obj = self.env['pos.order.line']
self.pc_obj = self.env['pos.config']
self.ps_obj = self.env['pos.session']
self.pc = self.env.ref('point_of_sale.pos_config_main')
self.rp_c2c = self.env.ref('base.res_partner_12')
self.ppl_c2c = self.env.ref('product.list0')
self.pp_usb = self.env.ref('product.product_product_48')
self.rp_spe = self.env.ref(
'pos_order_pricelist_change.partner_surcharge')
self.ppl_spe = self.env.ref(
'pos_order_pricelist_change.pricelist_surcharge')
# Test Section
def test_01_default_price_list(self):
"""[Regression Test] Sale with default Pricelist"""
cr, uid = self.cr, self.uid
# Getting object
pc_id = self.imd_obj.get_object_reference(
cr, uid, 'point_of_sale', 'pos_config_main')[1]
rp_c2c_id = self.imd_obj.get_object_reference(
cr, uid, 'base', 'res_partner_12')[1]
ppl_c2c_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'list0')[1]
pp_usb_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'product_product_48')[1]
# Opening Session
self.ps_obj.create(cr, uid, {
'config_id': pc_id,
})
self.ps_obj.create({'config_id': self.pc.id})
# create Pos Order
po_id = self.po_obj.create(cr, uid, {
'partner_id': rp_c2c_id,
'pricelist_id': ppl_c2c_id,
po = self.po_obj.create({
'partner_id': self.rp_c2c.id,
'pricelist_id': self.ppl_c2c.id,
'lines': [[0, False, {
'product_id': pp_usb_id,
'product_id': self.pp_usb.id,
'qty': 1,
}]],
})
pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
po = self.po_obj.browse(cr, uid, po_id)
res = self.pol_obj.onchange_product_id(
cr, uid, po.lines[0].id, po.pricelist_id.id,
po.lines[0].product_id.id, po.lines[0].qty)
res = po.lines[0].onchange_product_id(
po.pricelist_id.id, po.lines[0].product_id.id, po.lines[0].qty)
self.assertEquals(
res['value']['price_subtotal'], pp_usb.list_price,
res['value']['price_subtotal'], self.pp_usb.list_price,
"Incorrect price for default pricelist!")
def test_02_partner_with_price_list_before(self):
"""[Regression Test] Sale with specific Pricelist"""
cr, uid = self.cr, self.uid
# Getting object
pc_id = self.imd_obj.get_object_reference(
cr, uid, 'point_of_sale', 'pos_config_main')[1]
rp_spe_id = self.imd_obj.get_object_reference(
cr, uid, 'pos_order_pricelist_change', 'partner_surcharge')[1]
ppl_spe_id = self.imd_obj.get_object_reference(
cr, uid, 'pos_order_pricelist_change', 'pricelist_surcharge')[1]
pp_usb_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'product_product_48')[1]
# Opening Session
self.ps_obj.create(cr, uid, {
'config_id': pc_id,
})
self.ps_obj.create({'config_id': self.pc.id})
# create Pos Order
po_id = self.po_obj.create(cr, uid, {
'partner_id': rp_spe_id,
'pricelist_id': ppl_spe_id,
po = self.po_obj.create({
'partner_id': self.rp_spe.id,
'pricelist_id': self.ppl_spe.id,
'lines': [[0, False, {
'product_id': pp_usb_id,
'product_id': self.pp_usb.id,
'qty': 1,
}]],
})
pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
po = self.po_obj.browse(cr, uid, po_id)
res = self.pol_obj.onchange_product_id(
cr, uid, po.lines[0].id, po.pricelist_id.id,
po.lines[0].product_id.id, po.lines[0].qty)
res = po.lines[0].onchange_product_id(
po.pricelist_id.id, po.lines[0].product_id.id, po.lines[0].qty)
self.assertEquals(
res['value']['price_subtotal'], pp_usb.list_price + 10,
res['value']['price_subtotal'], self.pp_usb.list_price + 10,
"Incorrect price for specific pricelist!")
def test_03_partner_with_price_list_after(self):
"""[Functional Test] Change pricelist after have set lines."""
cr, uid = self.cr, self.uid
# Getting object
pc_id = self.imd_obj.get_object_reference(
cr, uid, 'point_of_sale', 'pos_config_main')[1]
ppl_spe_id = self.imd_obj.get_object_reference(
cr, uid, 'pos_order_pricelist_change', 'pricelist_surcharge')[1]
ppl_c2c_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'list0')[1]
pp_usb_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'product_product_48')[1]
# Opening Session
self.ps_obj.create(cr, uid, {
'config_id': pc_id,
})
self.ps_obj.create({'config_id': self.pc.id})
# create Pos Order
po_id = self.po_obj.create(cr, uid, {
'pricelist_id': ppl_c2c_id,
po = self.po_obj.create({
'pricelist_id': self.ppl_c2c.id,
'lines': [[0, False, {
'product_id': pp_usb_id,
'product_id': self.pp_usb.id,
'qty': 1,
}]],
})
po = self.po_obj.browse(cr, uid, po_id)
res = self.po_obj.onchange_pricelist_id(
cr, uid, po.id, ppl_spe_id, po.lines)
res = po.onchange_pricelist_id()
self.assertNotEquals(
res.get('warning', False), False,
"Need warning!")
pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
# Change now pricelist
self.po_obj.write(cr, uid, [po_id], {'pricelist_id': ppl_spe_id})
self.po_obj.action_recompute_pricelist(cr, uid, [po.id])
po = self.po_obj.browse(cr, uid, po_id)
po.write({'pricelist_id': self.ppl_spe.id})
po.action_recompute_pricelist()
po = self.po_obj.browse(po.id)
self.assertEquals(
po.amount_total, pp_usb.list_price + 10,
"Recompute with pricelist error")
def test_04_partner_without_price_list_after(self):
"""[Functional Test] Unset pricelist after have set lines."""
cr, uid = self.cr, self.uid
# Getting object
pc_id = self.imd_obj.get_object_reference(
cr, uid, 'point_of_sale', 'pos_config_main')[1]
pp_usb_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'product_product_48')[1]
ppl_c2c_id = self.imd_obj.get_object_reference(
cr, uid, 'product', 'list0')[1]
# Opening Session
self.ps_obj.create(cr, uid, {
'config_id': pc_id,
})
# create Pos Order
po_id = self.po_obj.create(cr, uid, {
'pricelist_id': ppl_c2c_id,
'lines': [[0, False, {
'product_id': pp_usb_id,
'qty': 1,
}]],
})
po = self.po_obj.browse(cr, uid, po_id)
res = self.po_obj.onchange_pricelist_id(
cr, uid, po.id, False, po.lines)
self.assertEquals(
res.get('warning', False), False,
"Doesn't need warning!")
po.amount_total, self.pp_usb.list_price + 10,
"Recompute with pricelist error.")

6
pos_order_pricelist_change/views/view.xml

@ -19,7 +19,7 @@
<!-- ********************************************************************** -->
<openerp>
<data>
<!-- View : pos.order -->
<!-- View : pos.order -->
<record id="view_pos_order_form" model="ir.ui.view">
<field name="name">pos.order.form</field>
<field name="model">pos.order</field>
@ -28,11 +28,7 @@
<header position="inside">
<button name="action_recompute_pricelist" string="Recompute With Pricelist" type="object" states="draft"/>
</header>
<field name="pricelist_id" position="attributes">
<attribute name="on_change">onchange_pricelist_id(pricelist_id, lines)</attribute>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save