Hi, I've created two modules.
The first one "Sale Quotation 2 Purchase Quotation" links a Sale Order with a Purchase Order and autofills the PO Lines with the values of the linked SO Lines.
So far, so good.
The second one "Purchase Order 2 Sale Order" gives me a lot of trouble.
It should do nearly the same like the first one, only in the other direction. It should autofill the SO Lines with the values of the linked PO Lines.
The problem is the "product_id_change" method. It checks whether a customer is defined before you can chose a product.
How can I solve it and get it work?
Many thanks for an adivce.
FIRST:
Sale Quotation 2 Purchase Quotation
<code></p>
class purchase_order(osv.osv):
_inherit = 'purchase.order'
_name = 'purchase.order'
STATE_SELECTION = [
('draft', 'Draft PO'),
('sent', 'RFQ Sent'),
('received', 'RFQ Received'),
('confirmed', 'Waiting Approval'),
('approved', 'Purchase Order'),
('except_picking', 'Shipping Exception'),
('except_invoice', 'Invoice Exception'),
('done', 'Done'),
('cancel', 'Cancelled')
]
_columns = {
'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True),
'purchase_quotation_id': fields.many2one('sale.order', 'Sale Quotation', domain=[('state','in',('draft','sent'))]),
}
_defaults = {
'state': 'draft',
'purchase_quotation_id': lambda self, cr, uid, context: context.get('purchase_quotation_id', False),
}
def onchange_purchase_order(self, cr, uid, id, purchase_quotation_id, partner_id, pricelist_id):
domain = []
value = []
if purchase_quotation_id:
sale = self.pool.get('sale.order').browse(cr,uid,purchase_quotation_id)
for line in sale.order_line:
vals = self.pool.get('purchase.order.line').onchange_product_id(cr, uid, id, pricelist_id, line.product_id.id, line.product_uom_qty, line.product_uom.id, partner_id)
vals['value'].update({
'product_id': line.product_id.id,
'state':'draft',
'move_ids':[],
'invoiced':0,
'invoice_lines':[],
})
value.append(vals['value'])
domain.append(vals['domain'])
return {'value': {'order_line': value}, 'domain': {'order_line': domain}}
class sale_order(osv.osv):
_inherit = "sale.order"
_name = "sale.order"
_columns = {
'sale_quotation': fields.one2many('purchase.order', 'purchase_quotation_id', 'Purchase Quotation'),
}
sale_order()
</code></p>
SECOND:
Purchase Quotation 2 Sale Quotation
<code><p>
class sale_order(osv.osv):
_inherit = 'sale.order'
_name = 'sale.order'
STATE_SELECTION = [
('draft', 'Draft Quotation'),
('sent', 'Quotation Sent'),
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sale Order'),
('manual', 'Sale to Invoice'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
]
_columns = {
'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True),
'sale_quotation_id': fields.many2one('purchase.order', 'Purchase Quotation', domain=[('state','in',('draft','sent'))]),
}
_defaults = {
'state': 'draft',
'sale_quotation_id': lambda self, cr, uid, context: context.get('sale_quotation_id', False),
}
def onchange_sale_order(self, cr, uid, id, sale_quotation_id, partner_id, pricelist_id):
domain = []
value = []
if sale_quotation_id:
purchase = self.pool.get('purchase.order').browse(cr,uid,sale_quotation_id)
for line in purchase.order_line:
>>>?? vals = self.pool.get('sale.order.line').product_id_change(cr, uid, id, pricelist_id, line.product_id.id, line.product_qty, line.product_uom.id, partner_id)
vals['value'].update({
'product_id': line.product_id.id,
'state':'draft',
'move_ids':[],
'invoiced':0,
'invoice_lines':[],
})
value.append(vals['value'])
domain.append(vals['domain'])
return {'value': {'order_line': value}, 'domain': {'order_line': domain}}
class purchase_order(osv.osv):
_inherit = "purchase.order"
_name = "purchase.order"
_columns = {
'purchase_quotation': fields.one2many('sale.order', 'sale_quotation_id', 'Sale Quotation'),
}
purchase_order()
</code></p>