Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
10 ตอบกลับ
9168 มุมมอง
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)
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 25
4953
2
ธ.ค. 24
7973
How to ORDER BY? [Odoo 10] แก้ไขแล้ว
2
พ.ย. 24
28785
2
พ.ค. 24
7655
3
มี.ค. 24
7107