38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = 'res.partner'
|
|
|
|
x_fc_part_catalog_ids = fields.One2many(
|
|
'fp.part.catalog', 'partner_id',
|
|
string='Part Catalog',
|
|
)
|
|
x_fc_part_count = fields.Integer(
|
|
string='Parts',
|
|
compute='_compute_part_count',
|
|
)
|
|
|
|
def _compute_part_count(self):
|
|
for partner in self:
|
|
partner.x_fc_part_count = self.env['fp.part.catalog'].search_count([
|
|
('partner_id', '=', partner.id),
|
|
('is_latest_revision', '=', True),
|
|
])
|
|
|
|
def action_view_parts(self):
|
|
self.ensure_one()
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': f'Parts — {self.name}',
|
|
'res_model': 'fp.part.catalog',
|
|
'view_mode': 'list,form',
|
|
'domain': [('partner_id', '=', self.id), ('is_latest_revision', '=', True)],
|
|
'context': {'default_partner_id': self.id},
|
|
'target': 'current',
|
|
}
|