# -*- coding: utf-8 -*- from odoo.exceptions import ValidationError class NumberHelper(object): def __init__(self): self.dic = {} def add(self, goods_id, second, main, can_not_change): data = [second, main, second, main] if can_not_change else [second, main, 0, 0] # 前2个:总数量;后2个:来自来源单据 if goods_id in self.dic: value = self.dic[goods_id] value[0] += data[0] value[1] += data[1] value[2] += data[2] value[3] += data[3] else: self.dic[goods_id] = data def get(self): return self.dic class DifferentHelper(object): # 来自来源单据的数据,不可修改 def __init__(self, not_change_helper, need_change_helper): self.not_change_dic = not_change_helper.get() self.need_change_dic = need_change_helper.get() self.new = {} self.add = {} self.sub = {} return def get(self): for goods_id, data in self.not_change_dic.items(): if goods_id not in self.need_change_dic: self.new[goods_id] = [data[0] - data[2], data[1] - data[3]] # 当前单据新添加的明细,才需要新建 continue change_data = self.need_change_dic[goods_id] # 以数量为准进行判断 if data[1] == change_data[1]: continue if data[1] > change_data[1]: if change_data[1] == change_data[3]: # 全部来自来源单据 self.new[goods_id] = [data[0] - change_data[0], data[1] - change_data[1]] else: # 说明有添加的数据。此时,只需要修改该数据即可 self.add[goods_id] = [data[0] - change_data[0], data[1] - change_data[1]] continue if change_data[1] == change_data[3]: # 全部来自来源单据 self.new[goods_id] = [change_data[0] - data[0], change_data[1] - data[1]] else: # 说明有添加的数据。此时,只需要修改该数据即可 self.sub[goods_id] = [change_data[0] - data[0], change_data[1] - data[1]] return self.new, self.add, self.sub