Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
10 Respostas
9177 Visualizações
I inherited  sale_order model and  worked  with mapping to send product  and  quantity  to customized module loading_slip but when i add two products and conform  sales to send product and quantities from order line to loading slip it give singleton error. how can i solve this? 
class sale_func(models.Model):
_inherit = 'sale.order'

add = fields.Char(string='Address')

#data mapping ###
@api.multi
def _create_slip(self):
inv_obj = self.env['loading.slip']
self.ensure_one()
slip = inv_obj.create({
'partner_id': self.partner_id.name,
'order_date': self.date_order,
'expiration_date': self.validity_date,
'so_no': self.name,

'invoice_line_ids': [(0, 0, {
'product_id': self.order_line.product_id.name,
'quantity': self.order_line.product_uom_qty,
})],
})
return slip
Avatar
Cancelar
Melhor resposta

Hi,

To solve the above problem you can try like this,

slip_id = inv_obj.create({
'partner_id': self.partner_id.name,
'order_date': self.date_order,
'expiration_date': self.validity_date,
'so_no': self.name,
})

After creating the record you can add the values to the one2many lines,

inv_line_list =[]
for orders in self.order_line:
inv_line_data = {
'product_id': orders.product_id.name,
        'connecting_field' : slip_id,
'quantity': orders.product_uom_qty,
}
inv_line_list.append(inv_line_data)
inv_line_obj = self.env['model_name_of_line']
for data_record in inv_line_list:
print inv_line_obj.create(data_record)

Thanks


Avatar
Cancelar
Autor

thanks Niyas for your reply.

But I got new error with them

DataError: invalid input syntax for integer: "clinker"

LINE 1: ...ALUES(nextval('sale_order_line_id_seq'), '0.000', 'clinker',...

^

what is the clinker ? is that the field that conects the two models ? like invoice_id in account.invoice & account.invoice.line

Autor

No, clinker is product name for sale order, which needs to be passed to customized module from sale.order

if you can share full code, it will be better. check with the type of newly added fields, as it is showing a error with the filed type

Autor

please check codes :)

Change this line 'product_id': orders.product_id.name , like this --> 'product_id': orders.product_id.id

Autor

product_id and quantity are still empty. I am making any mistake on the code

Melhor resposta

is this a working suggestion, please let us know.
Thanks

Avatar
Cancelar
Autor Melhor resposta
This  is  my code after your suggestion 

class sale_func(models.Model):
_inherit = 'sale.order'


# data mapping ###
@api.multi
def _create_slip(reco):
inv_obj = reco.env['loading.slip']
reco.ensure_one()
slip_id = inv_obj.create({
'partner_id': reco.partner_id.name,
'order_date': reco.date_order,
'expiration_date': reco.validity_date,
'so_no': reco.name,
})
    inv_line_list = []
    for orders in reco.order_line:
    inv_line_data = {
      'product_id': orders.product_id.name,
    'connecting_field': slip_id,
      'quantity': orders.product_uom_qty,
    }
inv_line_list.append(inv_line_data)

    inv_line_obj = reco.env['loading.product']
    for data_record in inv_line_list:
    return inv_line_obj.create(data_record)
ORM of loading slip module:
class LoadingSlip(models.Model):
_name = 'loading.slip'
_description = 'loading information'
invoice_line_ids = fields.One2many('loading.product', 'bh_id', 'Loading ID')
partner_id = fields.Char("गार्हक",store=True)
order_date = fields.Date("मिति")
expiration_date = fields.Date("रुजु मिति")
truck_no=fields.Char("गाडी नं.")
so_no=fields.Char(string="सि.नं.",store=True)

# many to one relaiton with loading.slip ###

class product_tree(models.Model):
_name ='loading.product'
_description = 'product tree'
bh_id = fields.Many2one('loading.slip','Loading ID')
sno = fields.Char("S.No")
product_id = fields.Char("Product Name",store=True)
quantity=fields.Char("Quantity",store=True)
Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
jul. 25
4953
2
dez. 24
7973
2
nov. 24
28785
2
mai. 24
7655
3
mar. 24
7107