跳至内容
菜单
此问题已终结
10 回复
9162 查看
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
形象
丢弃
最佳答案

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


形象
丢弃
编写者

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

编写者

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

编写者

please check codes :)

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

编写者

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

最佳答案

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

形象
丢弃
编写者 最佳答案
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)
形象
丢弃
相关帖文 回复 查看 活动
2
7月 25
4951
2
12月 24
7972
2
11月 24
28784
2
5月 24
7655
3
3月 24
7107