Skip to Content
Menu
This question has been flagged
1493 Views

Hi, 

I have a customer that pays in a weird way. They advance us a certain amount per product one week after delivery. Therefore i have created a new model "Advance". In this model it pulls the SO lines and allows me to input the prices and amounts paid for. Since they submit one payment a week for all items delivered the previous week, i want to be able to select multiple SO's and generate an advance that contains all SO lines. I have the following code in a wizard:

def create_advances(self):
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
sale_orders.create_advance()

This is the code in the sale.order model:

def prepare_advance(self):
self.ensure_one()
advance_vals = {
'advance_lines': [],
}
return advance_vals

def create_advance(self):
advance_vals_list = []
for order in self:
        advance_vals = order.prepare_advance()
for line in order.order_line:
advance_vals['advance_lines'].append((0, 0, line.prepare_advance_line()))
advance_vals_list.append(advance_vals)
    moves = self.env['peak.advance'].with_context(default_type='draft').create(advance_vals_list)
return moves

And the code in the sale.order.line

def prepare_advance_line(self):
self.ensure_one()
return {
'sale_line_ids': self.id,
'product_id': self.product_id.id,
'shipped_qty': self.qty_to_invoice,
'do': self.order_id.do,
'shipping_id': self.order_id.partner_shipping_id.id,
'ship_date': self.order_id.shipping_date,
'ordered_qty': self.product_uom_qty,
}


It works to generate an advance. The only problem is when i select multiple SO's, it only generates the SO lines from the lowest SO.

Avatar
Discard