Skip to content

Commit 0eb6455

Browse files
committed
IMP IMPORTANT imprrovements on product pack, get pack with sale order constraint
1 parent 2de36bf commit 0eb6455

12 files changed

+169
-273
lines changed

product_pack/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
##############################################################################
33
# For copyright and license notices, see __openerp__.py file in root directory
44
##############################################################################
5-
from . import pack
6-
from . import product
7-
from . import sale_order_line_pack_line
8-
from . import sale_order_line
9-
from . import sale_order
5+
from . import models

product_pack/__openerp__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
##############################################################################
2121
{
2222
'name': 'Product Pack',
23-
'version': '8.0.1.0.0',
23+
'version': '8.0.1.1.0',
2424
'category': 'Product',
2525
'sequence': 14,
2626
'summary': '',
2727
'description': """
2828
Product Pack
2929
============
30-
# TODO que el boton de abrir lineas de un pack habra una form para configurar eso.
3130
# TODO implementar totalice en price get
3231
# TODO ver de permitir packs dentro de packs (robar de v7)
3332
# TODO calcular correctamente pack virtual available para negativos
@@ -53,8 +52,8 @@
5352
'data': [
5453
'security/ir.model.access.csv',
5554
'security/product_security.xml',
56-
'pack_view.xml',
57-
'sale_view.xml',
55+
'views/pack_view.xml',
56+
'views/sale_view.xml',
5857
],
5958
'demo': [
6059
],

product_pack/models/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- encoding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in root directory
4+
##############################################################################
5+
from . import pack
6+
from . import product
7+
from . import sale_order_line_pack_line
8+
from . import sale_order_line
9+
from . import sale_order

product_pack/pack.py product_pack/models/pack.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ class product_pack(models.Model):
1818
'product.product', 'Product', required=True)
1919

2020
@api.multi
21-
def get_sale_order_line_vals(self, line, order, sequence, fiscal_position):
21+
def get_sale_order_line_vals(self, line, order):
2222
self.ensure_one()
23-
sequence += 1
2423
# pack_price = 0.0
2524
subproduct = self.product_id
2625
quantity = self.quantity * line.product_uom_qty
2726

28-
tax_ids = self.env['account.fiscal.position'].map_tax(
27+
tax_ids = order.fiscal_position.map_tax(
2928
subproduct.taxes_id)
3029
tax_id = [(6, 0, tax_ids)]
3130

@@ -65,7 +64,6 @@ def get_sale_order_line_vals(self, line, order, sequence, fiscal_position):
6564
'name': '%s%s' % (
6665
'> ' * (line.pack_depth + 1), subproduct_name
6766
),
68-
'sequence': sequence,
6967
# 'delay': subproduct.sale_delay or 0.0,
7068
'product_id': subproduct.id,
7169
# 'procurement_ids': (

product_pack/product.py product_pack/models/product.py

+13
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,16 @@ class product_template(models.Model):
121121
'Pack?',
122122
help='Is a Product Pack?',
123123
)
124+
125+
# @api.model
126+
# def _price_get(self, products, ptype='list_price'):
127+
# res = super(product_template, self)._price_get(
128+
# products, ptype=ptype)
129+
# for product in products:
130+
# if (
131+
# product.pack and
132+
# product.pack_price_type == 'totalice_price'):
133+
# # TODO should use price and not list_price
134+
# res[product.id] = sum(product.mapped(
135+
# 'pack_line_ids.product_id.list_price'))
136+
# return res

product_pack/models/sale_order.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- encoding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in root directory
4+
##############################################################################
5+
from openerp import models, api
6+
7+
8+
class sale_order(models.Model):
9+
_inherit = 'sale.order'
10+
11+
@api.model
12+
def create(self, vals):
13+
result = super(sale_order, self).create(vals)
14+
result.expand_packs()
15+
return result
16+
17+
@api.multi
18+
def write(self, vals):
19+
result = super(sale_order, self).write(vals)
20+
if vals.get('order_line'):
21+
self.expand_packs()
22+
return result
23+
24+
# def copy(self, cr, uid, id, default={}, context=None):
25+
# line_obj = self.pool.get('sale.order.line')
26+
# result = super(sale_order, self).copy(cr, uid, id, default, context)
27+
# sale = self.browse(cr, uid, result, context)
28+
# for line in sale.order_line:
29+
# if line.pack_parent_line_id:
30+
# line_obj.unlink(cr, uid, [line.id], context)
31+
# self.expand_packs(cr, uid, sale.id, context)
32+
# return result
33+
34+
@api.one
35+
def expand_packs(self):
36+
"""
37+
"""
38+
pack_lines = self.order_line.filtered(
39+
lambda l: l.state == 'draft' and
40+
l.product_id.pack and
41+
not l.product_id.sale_order_pack)
42+
print 'pack_lines', pack_lines
43+
while pack_lines:
44+
pack_lines = pack_lines.update_pack_lines()
45+
46+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

product_pack/sale_order_line.py product_pack/models/sale_order_line.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,49 @@ class sale_order_line(models.Model):
3939
'Lines in pack'
4040
)
4141

42+
@api.multi
43+
def update_pack_lines(self):
44+
pack_lines = self.env['sale.order.line']
45+
for line in self:
46+
for subline in line.product_id.pack_line_ids:
47+
vals = subline.get_sale_order_line_vals(
48+
line, line.order_id)
49+
vals['sequence'] = line.sequence
50+
existing_subline = line.search([
51+
('product_id', '=', subline.product_id.id),
52+
('pack_parent_line_id', '=', line.id),
53+
], limit=1)
54+
# if subline already exists we update, if not we create
55+
if existing_subline:
56+
existing_subline.write(vals)
57+
else:
58+
new_line = line.create(vals)
59+
if (
60+
new_line.state == 'draft' and
61+
new_line.product_id.pack and
62+
not new_line.product_id.sale_order_pack):
63+
pack_lines += new_line
64+
return pack_lines
65+
4266
@api.multi
4367
def button_save_data(self):
4468
return True
4569

4670
@api.multi
47-
def button_details(self):
48-
context = self.env.context.copy()
49-
context['view_buttons'] = True
71+
def action_pack_detail(self):
72+
view_id = self.env['ir.model.data'].xmlid_to_res_id(
73+
'product_pack.view_order_line_form2')
5074
view = {
5175
'name': _('Details'),
5276
'view_type': 'form',
5377
'view_mode': 'form',
5478
'res_model': 'sale.order.line',
55-
'view_id': False,
79+
'view_id': view_id,
5680
'type': 'ir.actions.act_window',
5781
'target': 'new',
5882
'readonly': True,
5983
'res_id': self.id,
60-
'context': context
84+
'context': self.env.context
6185
}
6286
return view
6387

product_pack/sale_order.py

-187
This file was deleted.

0 commit comments

Comments
 (0)