Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3109 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 22
2901
0
ธ.ค. 24
969
Import Data From Another Model แก้ไขแล้ว
1
มี.ค. 24
2001
1
มิ.ย. 23
12005
0
ม.ค. 23
2766