Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
10 Trả lời
9173 Lượt xem
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
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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

Tác giả

please check codes :)

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

Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
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)
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
4953
2
thg 12 24
7973
2
thg 11 24
28785
2
thg 5 24
7655
3
thg 3 24
7107