Skip to Content
Menu
This question has been flagged

from email.policy import default
from attr import fields from 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")

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'
return view_invoices
defaction_submit_paid(self):

self.state = 'paid'

view_paid = self.env.ref('foodstore.action_invoice_paid').read()[0]

view_paid['domain'] = [('state', '=', 'paid')]

view_paid['target'] = 'main'
returnview_paid

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')

defaction_calculate_price(self):

for data in self:

total_prices = data.total_price 

total_prices = data.sale_price * data.product_qty

data.total_price = total_prices


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):

for data in self:

total_prices = data.total_price

total_prices = data.sale_price * data.product_qty

data.total_price = total_prices


Here above is my code, basically, i want to change a record(state) using one button(action_submit_paid), and its solve actually, but the record from the other models which is fashion.order that has similar state still there, i want to change the state too, to make it hide from menu ordered in model order. any idea how to do it?

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 22
2226
2
Jul 20
25446
1
May 16
3206
1
Mar 15
8921
0
Mar 15
2660