跳至內容
選單
此問題已被標幟
1 回覆
3320 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 22
3054
0
12月 24
1299
1
3月 24
2341
1
6月 23
12340
0
1月 23
3026