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

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


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
Best Answer

You can access any model record as long as you having its id

assume that your model name is fashion.order and you want to change the state of a record with id = model_id, you will do this:
record = request.env['fashion.order'].browse(model_id)
record.state = your_new_state

I don't see fashion.order model in your code, so you need to fiqure out how to get its id

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 22
2062
0
Dec 24
4
1
Mar 24
832
1
Jun 23
10727
0
Jan 23
1558