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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
How to ORDER BY? [Odoo 10]
Solved
|
|
2
Nov 24
|
25064 | |
|
2
May 24
|
5512 | ||
|
3
Mar 24
|
4961 | ||
|
0
Mar 24
|
261 | ||
|
3
Feb 24
|
11415 |