Skip to Content
Menu
This question has been flagged
1 Reply
2154 Views

fromemail.policyimportdefault
fromattrimportfieldsfrom odoo import models, fields, api
classFashionOrder(models.Model):_name = 'fashion.order'#untuk lead_rec_name = 'order_name'
customer_name = fields.Many2one('fashion.customer', string="Name")order_name = fields.Char("Order Name", default="ORDER_")notes = fields.Char("Notes")order_line = fields.One2many('fashion.order.lines','order_id', string = "Order Lines")#save referensi dari penjelasan detailtotalorder_price = fields.Float(string="Total Order Price", readonly=True, store=True, compute="_compute_total_order_price")
state = fields.Selection([ ('lead', 'Lead'), ('ordered', 'Ordered'), ('paid', 'Paid') ], default='lead', string="Status", required=True)

defaction_submit_order(self):forainself:a.state = 'ordered'iDs = []fordataina.order_line:iDs.append(data['product_id']) #masih coba2# iDs = self.env[data.order_id] #coba2 codeprint("INI DATA APA",iDs)view_ordered = self.env.ref('foodstore.action_fashion_order').read()[0]view_ordered['domain'] = [('state', '=', 'ordered')]view_ordered['target'] = 'main'
order_rec = {'invoice_customer': self.customer_name.customername,'totalinvoice_price': self.totalorder_price,'state': self.state,'invoice_lines': [(6, 0, [iDs])], }order = self.env['fashion.invoice'].create(order_rec)print("CETAK ORDER REC",order_rec)print("CETAK ORDER REC",order)
returnview_ordered
defaction_delete(self):print('', self.order_name)self.unlink()view_orders = self.env.ref('foodstore.action_fashion_order').read()[0]view_orders['target'] = 'main'
returnview_orders

@api.depends('order_line.total_price')def_compute_total_order_price(self):print('ORDERAN', self)forrecordinself:current_price = 0print('ALL_PRODUCT', record.order_line)forproductinrecord.order_line:print('PRODUCT_NAME', product.product_id.name)current_price += product.total_priceprint('TOTAL_JUMLAH', current_price)record.totalorder_price = current_price
classFashionOrderLines(models.Model):_name = 'fashion.order.lines'
product_id = fields.Many2one('fashion.product', string="Product Name")product_qty = fields.Integer(string = "Quantity", default="1")order_id = fields.Many2one('fashion.order', string="Order ID")
order_code = fields.Char("Order Code", default="ORDER-")price_id = fields.Float(related='product_id.price', string="Price")sale_price = fields.Float(related='price_id', string="Sale Price", readonly=False)total_price = fields.Float("Total Price", store=True, compute="action_calculate_price")

@api.depends('sale_price','product_qty') #perubahan sebuah dari python dan tampilan defaction_calculate_price(self):total_prices = self.total_pricetotal_prices = self.sale_price * self

.product_qtyself.total_price = total_prices


and

fromemail.policyimportdefault
fromattrimportfieldsfrom odoo import models, fields, api
classFashionInvoice(models.Model):_name = 'fashion.invoice'_rec_name = 'invoice_name'
invoice_name = fields.Char("Invoice Name", default="INVOICE-NAME-")invoice_code = fields.Char("Invoice Code", default="INVOICE-ID")invoice_customer = fields.Char("Customer", default="INVOICE-ID")totalinvoice_price = fields.Float("Total Invoice Price")invoice_lines = fields.One2many('fashion.invoice.line','invoice_id', string="Invoice Line")# invoice_order_line = fields.One2many('fashion.invoice.line.','invoice_id', string = "Order Lines")# invoice_order_line = fields.Char(string = "Order Lines")state = fields.Selection([ ('ordered', 'Ordered'), ('paid', 'Paid') ], default='ordered', string="Status", required=True)
defaction_delete(self):self.unlink()view_invoices = self.env.ref('foodstore.action_invoice_order').read()[0]view_invoices['target'] = 'main'
returnview_invoices

classInvoiceLine(models.Model):_name = 'fashion.invoice.line'
product_id = fields.Many2one('fashion.product', string="Product Name")product_qty = fields.Integer(string = "Quantity", default="1")invoice_id = fields.Many2one('fashion.invoice', string="Invoice ID")
order_code = fields.Char("Order Code", default="ORDER-")price_id = fields.Float(related='product_id.price', string="Price")sale_price = fields.Float(related='price_id', string="Sale Price", readonly=False)total_price = fields.Float("Total Price", store=True, compute="action_calculate_price")

@api.depends('sale_price','product_qty') #perubahan sebuah dari python dan tampilan defaction_calculate_price(self):total_prices = self.total_pricetotal_prices = self.sale_price * self.product_qtyself.total_price = total_prices


i want to pass the record of product from order_line to invoice_lines but i got an error. any idea how to solve it?

Avatar
Discard
Best Answer

Hello Syah

It is difficult to read and debug your code from question. However i have make it correct to solve your issue.

 to update one2many field we have to pass list of ids and you have passed list record sets( check iDs.append(data['product_id'])).

your following code is incorrect

iDs = []
for data in a.order_line:
iDs.append(data['product_id']) #masih coba2# iDs = self.env[data.order_id] #coba2 codeprint("INI DATA APA",iDs)

please check following correct code to pass list of ids :

'invoice_lines': [(6, 0, a.order_line.mapped('product_id').ids)]


def action_submit_order(self):
for a in self:
a.state = 'ordered'
view_ordered = self.env.ref('foodstore.action_fashion_order').read()[0]
view_ordered['domain'] = [('state', '=', 'ordered')]
view_ordered['target'] = 'main'
order_rec = {
'invoice_customer': self.customer_name.customername,
'totalinvoice_price': self.totalorder_price,
'state': self.state,
'invoice_lines': [(6, 0, a.order_line.mapped('product_id').ids)]
}
order = self.env['fashion.invoice'].create(order_rec)
print("CETAK ORDER REC",order_rec)
print("CETAK ORDER REC",order)
return view_ordered

Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

Avatar
Discard
Related Posts Replies Views Activity
0
Jan 23
819
2
Oct 21
2119
0
Feb 20
2496
0
Mar 15
2532
1
Mar 15
3188