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

I have 2 model: contract, tenant.

I want to know tenant_id have in contract. 


Model Contract: 

class PmaContract(models.Model):    
​_name = "pma.contract"   
​_inherit = ["mail.thread", "mail.activity.mixin"]   
​_description = "Manage contract"
    ​state = fields.Selection([
​("draft", "Draft"),           
​("to_link", "To link"),
          ("active", "Active"),           
​("expired", "Expired"),           
​("liquidated", "Liquidated")],       
​string="Status",       
​copy=False, index=True, readonly=True, store=True)
    ​lessor = fields.Many2one("res.users",string="Party A (Lessor)",store=True,        required=True,    )
    apartment = fields.Many2one("pma.apartment", string="Apartment name", required=True)
    room = fields.Many2one("pma.apartment.room",string="Room name", domain="[('apartment', '=', apartment)]",        ondelete="restrict",        store=True,        required=True,    )    floor = fields.Many2one(related="room.floor")
    duration_from = fields.Date(string="From", store=True, required=True)    duration_to = fields.Date(string="To", store=True, required=True)
    lessee = fields.Many2one("pma.tenant", string="Representative", store=True, ondelete="restrict", required=True, domain="[('owner', '=', lessor)]",    )
​name = fields.Char(string="Contract ID", compute="_compute_name", store=True)   
​member = fields.Many2many("pma.tenant", store=True, string="Member",domain="[('owner', '=', lessor), ('id', '!=', lessee)]",)

Model Tenant: class PmaTenant(models.Model):   
​_inherit = "pma.tenant"
    ​contract_id = fields.One2many("pma.contract", "lessee", string="Contract", copy=True)
I want to get Tenant(lessee) when contract have status = "active", "liquidated" and don't have in contract.

Please help me ....

아바타
취소
작성자 베스트 답변

I have 2 model: Contract & Room. 


In model room I have a selection field to set state for room. 


They are my model:


- Room:

	​
class PmaApartmentRoom(models.Model):    
​_inherit = "pma.apartment.room"
    contract = fields.One2many("pma.contract", "room", string="Contract")
    state = fields.Selection([
​ ​("available", "Available"),
​ ​("rented", "Rented")],
​ ​string="Status", copy=False,
​ ​index=True, readonly=True, store=True, tracking=True)
  class PmaContract(models.Model):   
​_name = "pma.contract"   
​_inherit = ["mail.thread", "mail.activity.mixin"]   
​_description = "Manage contract"
    state = fields.Selection([
​ ​("draft", "Draft"),           
​ ​("to_link", "To link"), 
        ​("active", "Active"),
        ("expired", "Expired"), 
        ("liquidated", "Liquidated")],       
​ ​string="Status", default="draft", copy=False,       
​ ​ index=True, readonly=True, store=True, tracking=True,)
   
​room = fields.Many2one("pma.apartment.room", string="Room name",        ​ ​domain="[('apartment', '=', apartment)]",        ​ ​ ​ ​ ​ ​ondelete="restrict", store=True, required=True, tracking=True)
State of contract = "active" => state of room = "rented".

State of contract in ["draft", "to_link", "expried", "liquidated"] => state of room = "available"


Please help me ....


아바타
취소
베스트 답변

Hi,

Use Odoo's domain filter to limit your search results to tenants (lessees) with contracts with the status "active" or "liquidated" but no other statuses. These domain requirements can help you achieve this:

tenants_active_liquidated_contracts = self.env['pma.tenant'].search([
    ('contract_id.state', 'in', ['active', 'liquidated']),
    ('contract_id', '!=', False),
])

# You currently have a list of tenants with active or liquidated contracts.
for tenant in tenants_active_liquidated_contracts:
    print("Tenant Name:", tenant.name)  # Replace 'name' with the actual field you want to display


To find tenants who meet the required criteria, we use the search method on the pma.tenant model. We use a domain filter to check if the contract_id field (One2many) is not empty, meaning the tenant has contracts. The state of the contracts (contract_id.state) is also checked to see if it falls within the category of "active" or "liquidated" statuses. The tenants who have contracts with the stated statuses and who don't have contracts with other statuses will be listed for you. The tenant information can then be accessed by iterating through this recordset as needed


Hope it helps

아바타
취소
베스트 답변

Hi,

Try like this in order to get tenants which satisfy your condition mentioned above,

tenant_ids = self.env['pma.tenant'].search(['|',('contract_id.state', 'in', ['active', 'liquidated']),
('contract_id', '=',False)])

Thanks

아바타
취소
관련 게시물 답글 화면 활동
1
3월 23
2732
0
12월 22
3351
0
6월 21
3200
1
12월 20
4179
0
6월 20
5775