首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >滤波器域域one2many到many2one

滤波器域域one2many到many2one
EN

Stack Overflow用户
提问于 2019-01-22 10:09:44
回答 1查看 128关注 0票数 0

例如,我有一个one2many字段,其中包含3个具有两个不同值的字段。这里我们假设区域是一个one2many字段

A区=汽车= 3000辆,自行车=2000年。 B区=汽车= 2500,自行车= 1500。 C区=汽车= 2000,自行车= 1000。

我为以后选择的字段提供了many2one字段(Ex )。(汽车和自行车)

和rate_fields作为计算的触发器字段(稍后存储值的位置)

重点是我要选择"A“区域,然后在many2one字段中选择"Car”

速率字段的输出是3000,

如果选择区域"B“,然后选择"Bike”,则速率字段的输出为1500。

如果用代码编写,则实现使用域语法多个条件的逐域筛选器。有人能帮我做一个示例代码吗?

也许这是一个参考,但我不能做适当的代码

多条件

在编程中

如果a=5或(b != 10,c= 12)

在开放的ERP领域过滤器

(a,'=',5),('&',('b',‘!’,10),('c','=',12))

https://stackoverflow.com/a/19070664/9228786

提前谢谢你

EN

回答 1

Stack Overflow用户

发布于 2019-01-25 22:01:28

关于更多的细节,我参考了your other question,但是你的问题都很令人困惑。据我所知,你的目标是选择一个区域,然后选择一个车辆类型。根据你的选择,你想看看利率。

无论您想要什么样的模型,计算都需要一个字段来选择区域,一个字段来选择车辆类型,一个字段来存储费率。

你的另一个问题的课程有点混乱,下面是我的建议。

您需要一个模型来跟踪(1)位置/区域,(2)车辆类型,(3)每个车辆类型在每个位置/区域收费,(4)一个模型来计算给定位置/区域的给定车辆类型的费率。

代码语言:javascript
运行
复制
class ParkingLocation(models.Model):
    _name = 'parking.location'
    _description = 'Parking Zones'

    name = fields.Char(string='Name')

class VehicleType(models.Model):
    _name = 'vehicle.type'
    _description = 'Types of Vehicles'

    name = fields.Char(string='Name')

class ZoneRate(models.Model):
    _name = 'zone.rate'
    _description = 'Define the rate for each Vehicle Type in each Zone'

    location_id = fields.Many2one('parking.location', string='Location', required='True')
    vehicle_type_id = fields.Many2one('vehicle.type', string='Vehicle Type')
    rate = fields.Float('Rate')

class ZoneRateLookup(models.Model):
    _name = 'zone.rate.lookup'
    _description = 'Calculate the rate for the chosen Zone and Vehicle Type'

    location_id = fields.Many2one('parking.location', string='Location', required='True')
    vehicle_type_id = fields.Many2one('vehicle.type', string='Vehicle Type')
    rate = fields.Float('Rate', compute='_compute_rate', store=True, readonly=True)

    @api.multi
    @api.depends('location_id', 'vehicle_type_id')
    def _compute_rate(self):
        rate_lookup_obj = self.env['zone.rate.lookup']
        for zone_rate in self:
            rate = rate_lookup_obj.search([('location_id', '=', zone_rate.location_id.id),
                                                     ('vehicle_type_id', '=', zone_rate.vehicle_type_id.id)])
            if not rate:
                raise ValidationError(_('No Rate found for that Vehicle Type in that Zone!')
            zone_rate.rate = rate.rate
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54305837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档