from email.policy importdefault
from attr import fields
from 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")
totalorder_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)
def action_submit_order(self):
self.state = 'ordered'
view_ordered = self.env.ref('foodstore.action_fashion_order').read()[0]
view_ordered['domain'] = [('state', '=', 'ordered')]
view_ordered['target'] = 'main'
invoice_line_value = []
for line in self.order_line:
invoice_line_value.append((0,0, {'product_id': line.product_id.id, }))
order_rec = {'invoice_customer': self.customer_name.customername,'totalinvoice_price': self.totalorder_price,'state': self.state,'invoice_lines': invoice_line_value, }
order = self.env['fashion.invoice'].create(order_rec)
return view_ordered
def action_delete(self):
print('', self.order_name)
self.unlink()
view_orders = self.env.ref('foodstore.action_fashion_order').read()[0]
view_orders['target'] = 'main'
return view_orders
@api.depends('order_line.total_price')
def_compute_total_order_price(self):
current_price = 0
for product in self.order_line:
current_price += product.total_price
self.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')
def action_calculate_price(self):
total_prices = self.total_price
total_prices = self.sale_price * self.product_qty
self.total_price = total_prices
Here above is my code, when i add 2 product directly, then save it, this error is appear. Any idea how to solve it?