3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
1 |
from osv import fields,osv |
2 |
||
3 |
class sale_order(osv.osv): |
|
4 |
_inherit = "sale.order" |
|
5 |
||
6 |
def _has_supplier_direct_delivery(self, cr, uid, ids, name, arg, context=None): |
|
7 |
res = {} |
|
8 |
for id in ids: |
|
9 |
cr.execute('select id from sale_order_line where is_supplier_direct_delivery=true and order_id=%d' % id) |
|
10 |
results = cr.fetchone() |
|
11 |
if results and len(results) > 0: |
|
12 |
res[id] = True |
|
13 |
else: |
|
14 |
res[id] = False |
|
15 |
return res |
|
16 |
||
17 |
_columns = { |
|
3424.1.1
by Raphaël Valyi
- sale_supplier_direct_delivery: |
18 |
'has_supplier_direct_delivery': fields.function(_has_supplier_direct_delivery, method=True, type='boolean', string="Has Supplier Direct Delivery", store=True, select=1),# 'composite_global_state': fields.function(_composite_global_state, method=True, type='char', size=64, string="Composite Global State"),#TODO |
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
19 |
}
|
20 |
||
21 |
||
22 |
def action_wait(self, cr, uid, ids, context={}): |
|
23 |
for order in self.browse(cr, uid, ids): |
|
24 |
for order_line in order.order_line: |
|
25 |
context.update( {'qty_uos': order_line.product_uom_qty}) |
|
26 |
if order_line.is_supplier_direct_delivery: #forced manually |
|
27 |
self.pool.get('sale.order.line').write(cr, uid, order_line.id, {'type': 'make_to_order', 'is_supplier_direct_delivery': True}) |
|
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
28 |
|
3853
by husen daudi
[FIX]Module:sale_supplier_direct_delivery Picking done on sale and purchase |
29 |
return super(sale_order, self).action_wait(cr, uid, ids, context) |
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
30 |
|
31 |
||
3378.1.2
by Raphaël Valyi
sale_supplier_direct_delivery: almost prod read (except report) |
32 |
#cross linking direct delivery sale orders and purchase orders
|
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
33 |
def action_ship_create(self, cr, uid, ids, *args): |
34 |
super(sale_order, self).action_ship_create(cr, uid, ids, *args) |
|
35 |
||
36 |
for so in self.browse(cr, uid, ids):#TODO ensure that works!!! Why only one po_id is returned from super method? |
|
37 |
for so_line in so.order_line: |
|
38 |
if so_line.is_supplier_direct_delivery: |
|
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
39 |
if not (so_line.procurement_id and so_line.procurement_id.related_direct_delivery_purchase_order): |
40 |
continue #Direct delivery impossible for that product; product might have its procurement options not properly configured |
|
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
41 |
po = so_line.procurement_id.related_direct_delivery_purchase_order |
42 |
if len(po.order_line) != 1: |
|
43 |
logger.notifyChannel('DIRECT DELIVERY', netsvc.LOG_ERROR, "Error purchase order with id %d doesn't have a single line" % po.id) |
|
44 |
else: |
|
45 |
self.pool.get('purchase.order.line').write(cr, uid, po.order_line[0].id, {'partner_address_id': so.partner_shipping_id.id, 'is_supplier_direct_delivery': True, 'sale_order_line':so_line.id}) |
|
46 |
self.pool.get('sale.order.line').write(cr, uid, so_line.id, {'purchase_order_line': po.order_line[0].id}) |
|
3378.1.2
by Raphaël Valyi
sale_supplier_direct_delivery: almost prod read (except report) |
47 |
|
48 |
#we remove the associated moves from Stock -> Customers as it will be replaced by moves Suppliers -> Customers
|
|
49 |
#see purchase_order.action_picking_create for more details
|
|
50 |
for move in so_line.move_ids: |
|
51 |
self.pool.get('stock.move').write(cr, uid, move.id, {'state': 'draft'}) |
|
52 |
self.pool.get('stock.move').unlink(cr, uid, [move.id]) |
|
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
53 |
|
54 |
return True |
|
55 |
||
56 |
sale_order() |
|
57 |
||
58 |
class sale_order_line(osv.osv): |
|
59 |
_inherit = "sale.order.line" |
|
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
60 |
|
3387.2.4
by Raphaël Valyi
work in progress |
61 |
def _is_supplier_direct_delivery_advised(self, cr, uid, ids, name, arg, context={}): |
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
62 |
res = {} |
63 |
for so_line in self.browse(cr, uid, ids): |
|
3387.2.4
by Raphaël Valyi
work in progress |
64 |
if so_line.product_id: |
65 |
product_id = so_line.product_id.id #we do that to pass the qty in context properly; we can't use the order_line directly since product_id_change doesn't have a sale.order line reference |
|
66 |
if context == None: |
|
67 |
context = {} |
|
68 |
||
69 |
context.update({'qty': so_line.product_uos_qty}) |
|
70 |
product_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context) |
|
71 |
res[so_line.id] = product_obj.is_direct_delivery_from_product |
|
72 |
else: |
|
73 |
res[so_line.id] = False |
|
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
74 |
return res |
75 |
||
76 |
||
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
77 |
_columns = { |
78 |
'is_supplier_direct_delivery': fields.boolean('Is Direct Delivery?'), |
|
3356.4.18
by Raphaël Valyi
improved sale_supplier_direct_delivery: almost production ready! |
79 |
'is_supplier_direct_delivery_advised': fields.function(_is_supplier_direct_delivery_advised, method=True, type='boolean', string="Is Supplier Direct Delivery Advised?"), |
3378.1.2
by Raphaël Valyi
sale_supplier_direct_delivery: almost prod read (except report) |
80 |
'purchase_order_line':fields.many2one('purchase.order.line', 'Related Purchase Order Line', required=False), |
81 |
'purchase_order': fields.related('purchase_order_line', 'order_id', type='many2one', relation='purchase.order', string='Related Purchase Order'), |
|
82 |
'purchase_order_state': fields.related('purchase_order', 'state', type='char', size=64, string='Purchase Order State'), |
|
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
83 |
}
|
84 |
||
85 |
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0, |
|
86 |
uom=False, qty_uos=0, uos=False, name='', partner_id=False, |
|
3829
by husen daudi
[FIX] onchange_product_id API changes in sale.order.line |
87 |
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False): |
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
88 |
|
89 |
result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, |
|
3829
by husen daudi
[FIX] onchange_product_id API changes in sale.order.line |
90 |
uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag) |
3356.4.2
by Raphaël Valyi
supplier to customer direct delivery module (for Loyalty Expert): first import |
91 |
|
92 |
if product: |
|
93 |
context = {'lang': lang, 'partner_id': partner_id, 'qty': qty} |
|
94 |
product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context) |
|
95 |
if product_obj.is_direct_delivery_from_product: |
|
96 |
result['value'].update({'type': 'make_to_order', 'is_supplier_direct_delivery': True}) |
|
97 |
return result |
|
98 |
||
99 |
sale_order_line() |