common_code1 = """ #若为True,只能审核后才能打印否则不控制 self.is_state_print=False self.is_state_print2=False self.is_state_print3=False self.is_state_print4=False """ common_code2 = """ # 处理转化率错误问题,多明细时修改detail为对应的字段名称并取消注释 # def check_percent_conversion(self): # error = [] # for rec in self.detail: # if hasattr(rec, 'goods_id') and hasattr(rec, 'main_unit_number') and hasattr(rec, 'second_unit_number') and rec.goods_id.main_second_rate: # second_rate = rec.goods_id.second_rate # main_rate = rec.goods_id.main_rate # if rec.main_unit_number / rec.second_unit_number == second_rate / main_rate: # continue # else: # error.append(rec.goods_id.name + '-主辅转化不正确请检查后重试') # if error: # raise ValidationError('--'.join(error)) # """ sale_order_code1 = """ self.un_out_store_number=self.total_main_unit_number-self.out_store_number """ # code 保存前 # code1 保存后 # code2 审核前 # code3 审核后 # code4撤销前 # code5撤销后 table_dict = { 'jc_supply_chain.sale_order': { 'code': '', 'code1': common_code1 + '\n' + sale_order_code1, 'code2': common_code2, 'code3': """ def get_setting_flow(self): res = self.env['setting_center.sale_type'].search([('sale_type_id', '=', self.sale_type_id.id)]).mapped( 'order_2_out_store_default') res = res and res[0] if not res: res = '10' return res #订单生成出库 def create_sale_out_store(self,flow): bill = self bill_value = { 'department_id': bill.department_id and bill.department_id.id, 'customer_id': bill.customer_id and bill.customer_id.id, 'staff_id': bill.salesmen_id and bill.salesmen_id.id, 'subordinate_customer_id': bill.subordinate_customer_id and bill.subordinate_customer_id.id, 'carrier_id': bill.carrier_id and bill.carrier_id.id, 'sale_type_id': bill.sale_type_id and bill.sale_type_id.id, 'store_id': bill.store_id and bill.store_id.id, 'car_no': bill.car_no, 'transfer_remark': bill.remark_transfer, 'driver_tel': bill.driver_tel, 'sale_order_id': bill.id, 'source_bill_id':bill.id, 'source_model_id':self.env['ir.model'].sudo().search([('model','=',bill._name)]).id } out_store_bill = self.env['jc_supply_chain.sale_out_store'].sudo().create([bill_value]) out_store_bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number, 'second_unit_number':i.second_unit_number, 'origin_price': i.origin_price, 'price': i.price, 'goods_id': i.goods_id.id, 'source_bill_type': '2', 'source_bill_id': self.id, 'source_detail_id': i.id, 'freight_price': i.freight_price, 'freight_money': i.freight_money, 'money_without_discount': i.money_without_discount, 'price_before_discount': i.price_before_discount, 'discount': i.discount, 'net_price': i.net_price, 'net_sales': i.net_sales, 'self_freight_price': i.self_freight_price, 'self_freight_money': i.self_freight_money }] for i in bill.detail]}) if flow == '20': out_store_bill.check() self.sale_out_store_id = out_store_bill.id self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',out_store_bill._name)]).id self.generate_bill_id=(self.generate_bill_id+','+str(out_store_bill.id)) if self.generate_bill_id else str(out_store_bill.id) flow=get_setting_flow(self) create_sale_out_store(self,flow) """, 'code4': """ #如果有已审核的销售出库不允许撤销销售订单 def check_sale_out_store(self,method_name): rec_name=[] bill_ids=[] for rec in self: generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False if generate_bill_id: res = self.env['jc_supply_chain.sale_out_store'].search([('id', 'in', generate_bill_id)]) if res: for _b in res: if _b.bill_state>='10': rec_name.append(_b.name) else: bill_ids.append(str(_b.id)) _b.unlink() else: res.unlink() generate_bill='' generate_model_id=False if rec_name: raise ValidationError('存在生成的已审核的销售出库单--{}--不允许{}'.format(','.join(rec_name), method_name)) if bill_ids: generate_bill=rec.generate_bill_id.split(',') for d in bill_ids: generate_bill.remove(d) rec.generate_bill_id= generate_bill rec.generate_model_id=False check_sale_out_store(self,'撤销') """, 'code5': """ """, }, 'jc_supply_chain.sale_out_store': { 'code': '', 'code1': common_code1, 'code2': common_code2, 'code3': """ #销售出库审核反写订单 from collections import defaultdict def check_out_store_rewrite_order(self, flag): res_dict=defaultdict(list) if self.sale_order_id: order_bill = self.env['jc_supply_chain.sale_order'].browse(self.sale_order_id.id) out_store_number = order_bill.out_store_number if flag==1: update_store_number = self.total_main_unit_number + out_store_number else: update_store_number = out_store_number -self.total_main_unit_number order_bill.out_store_number = update_store_number order_bill.un_out_store_number = order_bill.total_main_unit_number - update_store_number if self.generate_bill: for rec in self.detail: res_dict[rec.order_bill_id].append(rec.main_unit_number) for k,v in res_dict.items(): out_store_number = k.out_store_number if flag == 1: update_store_number = sum(v) + out_store_number else: update_store_number = out_store_number-sum(v) k.out_store_number = update_store_number k.un_out_store_number = k.total_main_unit_number - update_store_number check_out_store_rewrite_order(self,1) #销售出库生成销售账单 def get_setting_flow(self): res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'out_store_2_account_default') return res def create_sale_account(self,flow): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'source_model_id': bill_model_id, 'source_bill_id': self.id, 'customer_id': self.customer_id and self.customer_id.id, 'store_id': self.store_id and self.store_id.id, 'salesmen_id': self.staff_id and self.staff_id.id, 'company_id': self.company_id and self.company_id.id, 'department_id': self.department_id and self.department_id.id, 'sale_type_id': self.sale_type_id and self.sale_type_id.id, 'subordinate_customer_id': self.subordinate_customer_id and self.subordinate_customer_id.id, 'carrier_id': self.carrier_id and self.carrier_id.id, 'car_no': self.car_no, 'remark_transfer': self.transfer_remark, 'driver_tel': self.driver_tel, } bill = self.env['jc_supply_chain.sale_account'].sudo().create([bill_value]) if self.detail: detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number, 'second_unit_number': i.second_unit_number, 'goods_id': i.goods_id.id, 'source_model_id': detail_model_id, 'source_bill_id': i.id, 'out_store_number': i.main_unit_number, 'origin_price': i.origin_price, 'freight_price': i.freight_price, 'freight_money': i.freight_money, 'self_freight_price': i.self_freight_price, 'self_freight_money': i.self_freight_money, 'net_price': i.net_price, 'net_sales': i.net_sales, 'remark': i.remark, 'price': i.price, 'money_without_discount': i.money_without_discount, 'price_before_discount': i.price_before_discount, 'discount': i.discount, }] for i in self.detail]}) if flow.get('create_type',False)=='20': bill.check() self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id) flow=get_setting_flow(self) if flow.get('create_type',False) !='1': create_sale_account(self,flow) """, 'code4': """ #如果有已审核的销售账单不允许撤销销售出库 def check_sale_out_store(self,method_name): rec_name=[] bill_ids=[] for rec in self: model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False if generate_bill_id: res = self.env[model_name].search([('id', 'in', generate_bill_id)]) if res: for _b in res: if _b.bill_state>='10': rec_name.append(_b.name) else: bill_ids.append(str(_b.id)) _b.unlink() else: res.unlink() generate_bill='' generate_model_id=False if rec_name: raise ValidationError('存在生成的已审核的销售账单--{}--不允许{}'.format(','.join(rec_name), method_name)) if bill_ids: generate_bill=rec.generate_bill_id.split(',') rec.remark= generate_bill for d in bill_ids: generate_bill.remove(d) rec.generate_bill_id= generate_bill rec.generate_model_id=False check_sale_out_store(self,'撤销') #销售出库撤销反写订单 from collections import defaultdict def check_out_store_rewrite_order(self, flag): res_dict=defaultdict(list) if self.sale_order_id: order_bill = self.env['jc_supply_chain.sale_order'].browse(self.sale_order_id.id) out_store_number = order_bill.out_store_number if flag==1: update_store_number = self.total_main_unit_number + out_store_number else: update_store_number = out_store_number -self.total_main_unit_number order_bill.out_store_number = update_store_number order_bill.un_out_store_number = order_bill.total_main_unit_number - update_store_number if self.generate_bill: for rec in self.detail: res_dict[rec.order_bill_id].append(rec.main_unit_number) for k,v in res_dict.items(): out_store_number = k.out_store_number if flag == 1: update_store_number = sum(v) + out_store_number else: update_store_number = out_store_number-sum(v) k.out_store_number = update_store_number k.un_out_store_number = k.total_main_unit_number - update_store_number check_out_store_rewrite_order(self,2) """, 'code5': """ """, }, 'jc_supply_chain.sale_account': { 'code': '', 'code1': common_code1, 'code2': common_code2, 'code3': """ #销售账单生成销售发票 def get_invoice_setting_flow(self): res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'sale_account_2_sale_invoice_default') return res def create_sale_invoice(self,flow,): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None, 'salesmen_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None, 'invoice_type_id': self.invoice_type_id.id if hasattr(self, 'invoice_type_id') else None, 'tax_bill_date': self.tax_bill_date if hasattr(self, 'tax_bill_date') else None, 'invoice_no': self.invoice_no if hasattr(self, 'invoice_no') else None, 'bank_account_id': self.bank_account_id.id if hasattr(self, 'bank_account_id') else None, 'bank_id': self.bank_id.id if hasattr(self, 'bank_id') else None, 'invoicing_object': self.invoicing_object if hasattr(self, 'invoicing_object') else None, 'contact_unit_id': self.contact_unit_id.id if hasattr(self, 'contact_unit_id') else None, 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None, 'company_id': self.company_id.id if hasattr(self, 'company_id') else None, 'department_id': self.department_id.id if hasattr(self, 'department_id') else None, 'sale_type_id': self.sale_type_id.id if hasattr(self, 'sale_type_id') else None, 'invoice_total_money': self.invoice_total_money if hasattr(self, 'invoice_total_money') else None, 'car_no': self.car_no if hasattr(self, 'car_no') else None, 'driver_tel': self.driver_tel if hasattr(self, 'driver_tel') else None, 'remark_transfer': self.remark_transfer if hasattr(self, 'remark_transfer') else None, 'carrier_id': self.carrier_id.id if hasattr(self, 'carrier_id') else None, 'source_bill_id': self.id, 'source_model_id': bill_model_id, } bill = self.env['jc_supply_chain.sale_invoice'].sudo().create([bill_value]) if self.detail: detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_account_detail')]).id bill.write({'invoice_detail': [[0, 0, { 'source_bill_type': '3', 'source_bill_id': self.id, 'source_detail_id': i.id, 'goods_invoice': i.goods_invoice if hasattr(i, 'goods_invoice') else None, 'transfer_price': i.freight_price if hasattr(i, 'frei') else None, 'transfer_money': i.freight_money if hasattr(i, 'freight_money') else None, 'tax_rate': i.tax_rate if hasattr(i, 'tax_rate') else None, 'tax_money': i.tax_money if hasattr(i, 'tax_money') else None, 'without_tax_money': i.without_tax_money if hasattr(i, 'without_tax_money') else None, 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None, 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None, 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None, 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None, 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None, 'price': i.price if hasattr(i, 'price') else None, 'money': i.money if hasattr(i, 'money') else None, }] for i in self.detail]}) bill.write({'bill_detail': [[0, 0, { 'source_bill_type': '3', 'source_bill_id': self.id, 'source_detail_id': i.id, 'bill_name': i.goods_id.name, 'date': i.date if hasattr(i, 'date') else None, 'store_id': i.store_id.id if hasattr(i, 'store_id') else None, 'main_unit_number_invoiced': i.main_unit_number_invoiced if hasattr(i, 'main_unit_number_invoiced') else None, 'main_unit_number_invoicing': i.main_unit_number_invoicing if hasattr(i, 'main_unit_number_invoicing') else None, 'money_invoiced': i.money_invoiced if hasattr(i, 'money_invoiced') else None, 'money_invoicing': i.money_invoicing if hasattr(i, 'money_invoicing') else None, 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None, 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None, 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None, 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None, 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None, 'price': i.price if hasattr(i, 'price') else None, 'money': i.money if hasattr(i, 'money') else None, 'remark': i.remark if hasattr(i, 'remark') else None, }] for i in self.detail]}) if flow.get('create_type',False)=='20': bill.check() self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id) flow=get_invoice_setting_flow(self) if flow.get('create_type',False) !='1': create_sale_invoice(self,flow) # 销售账单生成收款单 def get_receipt_setting_flow(self): res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'sale_account_2_sale_receipt_default') return res def create_sale_receipt(self,flow): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'company_id':flow.get('company_id',False) , 'department_id': self.department_id.id if hasattr(self, 'department_id') else None, 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None, 'receipt_type_id': flow.get('receipt_type_id',False), 'salesmen_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None, 'receipt_account_id': flow.get('receipt_account_id',False) , 'receipt_account': self.receipt_account if hasattr(self, 'receipt_account') else None, 'incoming_account_id': self.incoming_account_id.id if hasattr(self, 'incoming_account_id') else None, 'incoming_account': self.incoming_account if hasattr(self, 'incoming_account') else None, 'money': self.total_money if hasattr(self, 'total_money') else None, 'contact_unit_id': self.contact_unit_id.id if hasattr(self, 'contact_unit_id') else None, 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None, 'source_bill_id': self.id, 'source_model_id': bill_model_id, } bill = self.env['jc_supply_chain.sale_receipt'].sudo().create([bill_value]) if flow.get('create_type',False)=='20': bill.check() self.generate_model2_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill2_id=(self.generate_bill2_id+','+str(bill.id)) if self.generate_bill2_id else str(bill.id) flow=get_receipt_setting_flow(self) if flow.get('create_type',False) !='1': create_sale_receipt(self,flow) """, 'code4': """ #有生成的销售发票和销售收款单不允许撤销 def uncheck_bill(self,method_name): def check_sale_out_store(self,method_name,flag): rec_name=[] bill_ids=[] for rec in self: if flag==1: model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False else: model_name=self.env['ir.model'].sudo().browse(self.generate_model2_id.id).model generate_bill_id=[int(i) for i in rec.generate_bill2_id.split(',')] if rec.generate_bill2_id else False if generate_bill_id: res = self.env[model_name].search([('id', 'in', generate_bill_id)]) if res: for _b in res: if _b.bill_state>='10': rec_name.append(_b.name) else: bill_ids.append(str(_b.id)) _b.unlink() else: res.unlink() generate_bill='' generate_model_id=False if rec_name: if flag==1: raise ValidationError('存在生成的已审核的销售发票--{}--不允许{}'.format(','.join(rec_name), method_name)) else: raise ValidationError('存在生成的已审核的销售收款--{}--不允许{}'.format(','.join(rec_name), method_name)) if bill_ids: if flag ==1: generate_bill=rec.generate_bill_id.split(',') else: generate_bill=rec.generate_bill2_id.split(',') for d in bill_ids: generate_bill.remove(d) if flag==1: rec.generate_bill_id= generate_bill rec.generate_model_id=False else: rec.generate_bill2_id= generate_bill rec.generate_model2_id=False check_sale_out_store(self,method_name,1) check_sale_out_store(self,method_name,2) uncheck_bill(self,'撤销') """, 'code5': """ """, }, 'jc_supply_chain.sale_chargeback': { 'code': '', 'code1': common_code1, 'code2': common_code2, 'code3': """ #销售退单生成退库 def get_invoice_setting_flow(self): res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'return_bill_2_return_store_default') return res def create_return_store(self,flow,): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'company_id': self.company_id.id if hasattr(self, 'company_id') else None, 'department_id': self.department_id.id if hasattr(self, 'department_id') else None, 'date': self.date if hasattr(self, 'date') else None, 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None, 'staff_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None, 'store_id': self.store_id.id if hasattr(self, 'store_id') else None, 'sale_type_id': self.sale_type_id.id if hasattr(self, 'sale_type_id') else None, 'provider_id': self.provider_id.id if hasattr(self, 'provider_id') else None, 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None, 'car_no': self.car_no if hasattr(self, 'car_no') else None, 'carrier_id': self.carrier_id.id if hasattr(self, 'carrier_id') else None, 'transfer_remark': self.transfer_remark if hasattr(self, 'transfer_remark') else None, 'driver_tel': self.driver_tel if hasattr(self, 'driver_tel') else None, 'source_bill_id': self.id, 'source_model_id': bill_model_id, } bill = self.env['jc_supply_chain.sale_return_store'].sudo().create([bill_value]) if self.detail: detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_account_detail')]).id bill.write({'detail': [[0, 0, { 'source_bill_type': '9', 'source_bill_id': self.id, 'source_detail_id': i.id, 'goods_place_id': i.goods_place_id.id if hasattr(i, 'goods_place_id') else None, 'goods_batch_id': i.goods_batch_id.id if hasattr(i, 'goods_batch_id') else None, 'remark': i.remark if hasattr(i, 'remark') else None, 'cost_price': i.cost_price if hasattr(i, 'cost_price') else None, 'cost_money': i.cost_money if hasattr(i, 'cost_money') else None, 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None, 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None, 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None, 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None, 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None, 'price': i.price if hasattr(i, 'price') else None, 'money': i.money if hasattr(i, 'money') else None,}] for i in self.detail]}) if flow.get('create_type',False)=='20': bill.check() self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id) flow=get_invoice_setting_flow(self) if flow.get('create_type',False) !='1': create_return_store(self,flow) """, 'code4': """ #如果有已审核的销售退库单不允许撤销 def check_sale_out_store(self,method_name): rec_name=[] bill_ids=[] for rec in self: model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False if generate_bill_id: res = self.env[model_name].search([('id', 'in', generate_bill_id)]) if res: for _b in res: if _b.bill_state>='10': rec_name.append(_b.name) else: bill_ids.append(str(_b.id)) _b.unlink() else: res.unlink() generate_bill='' generate_model_id=False if rec_name: raise ValidationError('存在生成的已审核的销售退库--{}--不允许{}'.format(','.join(rec_name), method_name)) if bill_ids: generate_bill=rec.generate_bill_id.split(',') rec.remark= generate_bill for d in bill_ids: generate_bill.remove(d) rec.generate_bill_id= generate_bill rec.generate_model_id=False check_sale_out_store(self,'撤销') """, 'code5': """ """, }, 'jc_supply_chain.sale_return_store': { 'code': '', 'code1': common_code1, 'code2': common_code2, 'code3': """ #销售退库单生成销售账单 def get_setting_flow(self): res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'return_store_2_return_invoice_default') return res def create_sale_account(self,flow): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'source_model_id': bill_model_id, 'source_bill_id': self.id, 'customer_id': self.customer_id and self.customer_id.id, 'store_id': self.store_id and self.store_id.id, 'salesmen_id': self.staff_id and self.staff_id.id, 'company_id': self.company_id and self.company_id.id, 'department_id': self.department_id and self.department_id.id, 'sale_type_id': self.sale_type_id and self.sale_type_id.id, 'subordinate_customer_id': self.subordinate_customer_id and self.subordinate_customer_id.id, 'carrier_id': self.carrier_id and self.carrier_id.id, 'car_no': self.car_no, 'remark_transfer': self.transfer_remark, 'driver_tel': self.driver_tel, } bill = self.env['jc_supply_chain.sale_account'].sudo().create([bill_value]) if self.detail: detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number*-1, 'second_unit_number': i.second_unit_number*-1, 'goods_id': i.goods_id.id, 'source_bill_type': '5', 'source_bill_id': self.id, 'source_detail_id': i.id, 'out_store_number': i.main_unit_number, 'origin_price': i.origin_price if hasattr(i,'orgin_price') else None, 'freight_price': i.freight_price, 'freight_money': i.freight_money, 'self_freight_price': i.self_freight_price, 'self_freight_money': i.self_freight_money, 'net_price': i.net_price, 'net_sales': i.net_sales, 'remark': i.remark, 'price': i.price, 'money_without_discount': i.money_without_discount, 'price_before_discount': i.price_before_discount, 'discount': i.discount, }] for i in self.detail]}) if flow.get('create_type',False)=='20': bill.check() self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id) flow=get_setting_flow(self) if flow.get('create_type',False) !='1': create_sale_account(self,flow) """, 'code4': """ #如果有已审核的销售账单不允许撤销 def check_sale_out_store(self,method_name): rec_name=[] bill_ids=[] for rec in self: model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False if generate_bill_id: res = self.env[model_name].search([('id', 'in', generate_bill_id)]) if res: for _b in res: if _b.bill_state>='10':+ rec_name.append(_b.name) else: bill_ids.append(str(_b.id)) _b.unlink() else: res.unlink() generate_bill='' generate_model_id=False if rec_name: raise ValidationError('存在生成的已审核的销售账单--{}--不允许{}'.format(','.join(rec_name), method_name)) if bill_ids: generate_bill=rec.generate_bill_id.split(',') rec.remark= generate_bill for d in bill_ids: generate_bill.remove(d) rec.generate_bill_id= generate_bill rec.generate_model_id=False check_sale_out_store(self,'撤销') """, 'code5': """ """, }, 'jc_supply_chain.transfer_out_store': { 'code': '', 'code1': common_code1, 'code2': common_code2, 'code3': """ #调拨出库生成调拨入库 def get_setting_flow(self): res = self.env['setting_center.transfer_type'].query_create_type(self.transfer_type_id.id,'transfer_out_2_in_type_default') return res def create_transfer_in_store(self,flow): bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id bill_value = { 'source_model_id': bill_model_id, 'source_bill_id': self.id, 'in_store_id': self.in_store_id.id, 'out_store_id': self.out_store_id.id, 'transfer_type_id': self.transfer_type_id.id, 'department_id': self.department_id.id, 'company_id': self.company_id.id, } bill = self.env['jc_supply_chain.transfer_in_store'].sudo().create([bill_value]) if self.detail: detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id bill.write({'detail': [[0, 0, { 'source_bill_type': '23', 'source_bill_id': self.id, 'source_detail_id': _.id, 'goods_id': _.goods_id.id, 'main_unit_number': _.main_unit_number, 'second_unit_number': _.second_unit_number, 'price': _.price, 'cost_price': _.cost_price, 'freight_price': _.freight_price, 'goods_place_id': _.goods_place_id.id, 'goods_batch_id': _.goods_batch_id.id, }] for _ in self.detail]}) if flow.get('create_type',False)=='20': bill.check() self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id self.generate_bill_id=bill.id flow=get_setting_flow(self) if flow.get('create_type',False) !='1': create_transfer_in_store(self,flow) """, 'code4': """ #如果有已审核的调拨入库单不允许撤销 def logic_sale_return_store(self): if self.generate_bill_id: model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model bill=self.env[model_name].sudo().search([('id','=',self.generate_bill_id)]) if bill.bill_state=='10' or bill.bill_state =='20': raise ValidationError('存在已审核或已完毕的调拨入库单--{}--不允许撤销当前调拨出库单'.format(bill.name)) else: bill.sudo().unlink() self.generate_bill_id=0 self.generate_model_id=False logic_sale_return_store(self) """, 'code5': """ """, }, }