콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
3392 화면

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
3113
0
12월 24
1366
1
3월 24
2425
1
6월 23
12439
0
1월 23
3134