Odoo 10-计算字段(第2部分)

时间:2018-10-08 07:11:51

标签: python odoo

这是我的课程和计算功能的字段:

half_pension = fields.Boolean(string='School catering', copy=False)
half_pension_begin_date = fields.Date(string='Start date school catering', copy=False)
half_pension_end_date = fields.Date(string='End date school catering', copy=False)
half_pension_id = fields.Many2one(comodel_name="ecole.halfpension.school", string="Restoration Place")
half_pension_days_value = fields.Integer(string='Days value', copy=False, store=True)
half_pension_binary_value = fields.Char(string='Binary value', copy=False, store=True)
half_pension_monday = fields.Boolean(string='Monday', copy=False, store=False, compute='convert_bin_dec')
half_pension_tuesday = fields.Boolean(string='Tuesday', copy=False, store=False, compute='convert_bin_dec')
half_pension_wednesday = fields.Boolean(string='Wednesday', copy=False, readonly="1")
half_pension_thursday = fields.Boolean(string='Thursday', copy=False, store=False, compute='convert_bin_dec')
half_pension_friday = fields.Boolean(string='Friday', copy=False, store=False, compute='convert_bin_dec')




# Function that converts to binary and synchronize a value in binary and days of the week
    @api.depends('half_pension_days_value')
    @api.onchange('half_pension',
                  'half_pension_monday',
                  'half_pension_tuesday',
                  'half_pension_thursday',
                  'half_pension_friday')
    def convert_bin_dec(self):
        for record in self:
            if record.half_pension:
                if record.half_pension_days_value != 0:
                    print "J'ai un nombre décimal"
                    # On transforme le total en valeur binaire (deviens string)
                    values = dec2bin(record.half_pension_days_value, 7)
                    record.half_pension_binary_value = values

                    list_values = []
                    for lettre in values:
                        list_values.append(lettre)

                    print list_values

                    # # On sépare dans des variables nos valeurs
                    if list_values[6] != '0':
                        record.half_pension_monday = True
                    else:
                        record.half_pension_monday = False
                    if list_values[5] != '0':
                        record.half_pension_tuesday = True
                    else:
                        record.half_pension_tuesday = False
                    if list_values[4] != '0':
                        record.half_pension_wednesday = True
                    else:
                        record.half_pension_wednesday = False
                    if list_values[3] != '0':
                        record.half_pension_thursday = True
                    else:
                        record.half_pension_thursday = False
                    if list_values[2] != '0':
                        record.half_pension_friday = True
                    else:
                        record.half_pension_friday = False
                # on récupère les valeur booleenne pour chaque enregistrement
                value_monday = record.half_pension_monday
                value_tuesday = record.half_pension_tuesday
                value_thursday = record.half_pension_thursday
                value_friday = record.half_pension_friday

                # On assigne une valeur si c'est True ou False à chaque jours
                if value_monday:
                    monday_decimal = 1
                else:
                    monday_decimal = 0

                if value_tuesday:
                    tuesday_decimal = 2
                else:
                    tuesday_decimal = 0

                if value_thursday:
                    thursday_decimal = 8
                else:
                    thursday_decimal = 0

                if value_friday:
                    friday_decimal = 16
                else:
                    friday_decimal = 0

                # On fait le total
                total_decimal = monday_decimal + tuesday_decimal + thursday_decimal + friday_decimal
                record.half_pension_days_value = total_decimal

                # On transforme le total en valeur binaire (deviens string)
                values = dec2bin(total_decimal, 7)
                record.half_pension_binary_value = values

                # On met le statut de l'inscription a 2 pour l'inscription cantine
                record.status_ws = "2"
            else:
                record.half_pension_days_value = 0
                record.half_pension_binary_value = "0000000"
                record.status_ws = "3"

该功能即将完成。可以。

麻烦的是,一方面,我想计算我的布尔值(基于字段“ half_pension_days_value”中基数中注册的十进制数),反之,计算字段“ half_pension_days_value''的值“,具体取决于选中的布尔值。

当前,如果我选择一个值,我的代码将起作用。当我在工作日打勾时,它也起作用(但是当我回来编辑录音时,并没有停留)。如果我只使用onchange装饰器('half_pension_days_value'),则我的工作日布尔值仍为False。

这里是一个视觉,可以更好地理解:

enter image description here

示例:当前,如果我将天数更改为3,则将检查星期一和星期二。很好,但是我希望自己可以检查(当前为只读)。我不知道我是否足够清楚,请随时让我知道。

皮质

0 个答案:

没有答案