123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- 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': """
- """,
- },
- }
|