work_logic_default.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. common_code1 = """
  2. #若为True,只能审核后才能打印否则不控制
  3. self.is_state_print=False
  4. self.is_state_print2=False
  5. self.is_state_print3=False
  6. self.is_state_print4=False
  7. """
  8. common_code2 = """
  9. # 处理转化率错误问题,多明细时修改detail为对应的字段名称并取消注释
  10. # def check_percent_conversion(self):
  11. # error = []
  12. # for rec in self.detail:
  13. # if hasattr(rec, 'goods_id') and hasattr(rec, 'main_unit_number') and hasattr(rec, 'second_unit_number') and rec.goods_id.main_second_rate:
  14. # second_rate = rec.goods_id.second_rate
  15. # main_rate = rec.goods_id.main_rate
  16. # if rec.main_unit_number / rec.second_unit_number == second_rate / main_rate:
  17. # continue
  18. # else:
  19. # error.append(rec.goods_id.name + '-主辅转化不正确请检查后重试')
  20. # if error:
  21. # raise ValidationError('--'.join(error))
  22. #
  23. """
  24. sale_order_code1 = """
  25. self.un_out_store_number=self.total_main_unit_number-self.out_store_number
  26. """
  27. # code 保存前
  28. # code1 保存后
  29. # code2 审核前
  30. # code3 审核后
  31. # code4撤销前
  32. # code5撤销后
  33. table_dict = {
  34. 'jc_supply_chain.sale_order': {
  35. 'code': '',
  36. 'code1': common_code1 + '\n' + sale_order_code1,
  37. 'code2': common_code2,
  38. 'code3': """
  39. def get_setting_flow(self):
  40. res = self.env['setting_center.sale_type'].search([('sale_type_id', '=', self.sale_type_id.id)]).mapped(
  41. 'order_2_out_store_default')
  42. res = res and res[0]
  43. if not res:
  44. res = '10'
  45. return res
  46. #订单生成出库
  47. def create_sale_out_store(self,flow):
  48. bill = self
  49. bill_value = {
  50. 'department_id': bill.department_id and bill.department_id.id,
  51. 'customer_id': bill.customer_id and bill.customer_id.id,
  52. 'staff_id': bill.salesmen_id and bill.salesmen_id.id,
  53. 'subordinate_customer_id': bill.subordinate_customer_id and bill.subordinate_customer_id.id,
  54. 'carrier_id': bill.carrier_id and bill.carrier_id.id,
  55. 'sale_type_id': bill.sale_type_id and bill.sale_type_id.id,
  56. 'store_id': bill.store_id and bill.store_id.id,
  57. 'car_no': bill.car_no,
  58. 'transfer_remark': bill.remark_transfer,
  59. 'driver_tel': bill.driver_tel,
  60. 'sale_order_id': bill.id,
  61. 'source_bill_id':bill.id,
  62. 'source_model_id':self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  63. }
  64. out_store_bill = self.env['jc_supply_chain.sale_out_store'].sudo().create([bill_value])
  65. out_store_bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number,
  66. 'second_unit_number':i.second_unit_number,
  67. 'origin_price': i.origin_price,
  68. 'price': i.price,
  69. 'goods_id': i.goods_id.id,
  70. 'source_bill_type': '2',
  71. 'source_bill_id': self.id,
  72. 'source_detail_id': i.id,
  73. 'freight_price': i.freight_price,
  74. 'freight_money': i.freight_money,
  75. 'money_without_discount': i.money_without_discount,
  76. 'price_before_discount': i.price_before_discount,
  77. 'discount': i.discount,
  78. 'net_price': i.net_price,
  79. 'net_sales': i.net_sales,
  80. 'self_freight_price': i.self_freight_price,
  81. 'self_freight_money': i.self_freight_money
  82. }] for i in bill.detail]})
  83. if flow == '20':
  84. out_store_bill.check()
  85. self.sale_out_store_id = out_store_bill.id
  86. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',out_store_bill._name)]).id
  87. self.generate_bill_id=(self.generate_bill_id+','+str(out_store_bill.id)) if self.generate_bill_id else str(out_store_bill.id)
  88. flow=get_setting_flow(self)
  89. create_sale_out_store(self,flow)
  90. """,
  91. 'code4': """
  92. #如果有已审核的销售出库不允许撤销销售订单
  93. def check_sale_out_store(self,method_name):
  94. rec_name=[]
  95. bill_ids=[]
  96. for rec in self:
  97. generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False
  98. if generate_bill_id:
  99. res = self.env['jc_supply_chain.sale_out_store'].search([('id', 'in', generate_bill_id)])
  100. if res:
  101. for _b in res:
  102. if _b.bill_state>='10':
  103. rec_name.append(_b.name)
  104. else:
  105. bill_ids.append(str(_b.id))
  106. _b.unlink()
  107. else:
  108. res.unlink()
  109. generate_bill=''
  110. generate_model_id=False
  111. if rec_name:
  112. raise ValidationError('存在生成的已审核的销售出库单--{}--不允许{}'.format(','.join(rec_name), method_name))
  113. if bill_ids:
  114. generate_bill=rec.generate_bill_id.split(',')
  115. for d in bill_ids:
  116. generate_bill.remove(d)
  117. rec.generate_bill_id= generate_bill
  118. rec.generate_model_id=False
  119. check_sale_out_store(self,'撤销')
  120. """,
  121. 'code5': """
  122. """,
  123. },
  124. 'jc_supply_chain.sale_out_store': {
  125. 'code': '',
  126. 'code1': common_code1,
  127. 'code2': common_code2,
  128. 'code3': """
  129. #销售出库审核反写订单
  130. from collections import defaultdict
  131. def check_out_store_rewrite_order(self, flag):
  132. res_dict=defaultdict(list)
  133. if self.sale_order_id:
  134. order_bill = self.env['jc_supply_chain.sale_order'].browse(self.sale_order_id.id)
  135. out_store_number = order_bill.out_store_number
  136. if flag==1:
  137. update_store_number = self.total_main_unit_number + out_store_number
  138. else:
  139. update_store_number = out_store_number -self.total_main_unit_number
  140. order_bill.out_store_number = update_store_number
  141. order_bill.un_out_store_number = order_bill.total_main_unit_number - update_store_number
  142. if self.generate_bill:
  143. for rec in self.detail:
  144. res_dict[rec.order_bill_id].append(rec.main_unit_number)
  145. for k,v in res_dict.items():
  146. out_store_number = k.out_store_number
  147. if flag == 1:
  148. update_store_number = sum(v) + out_store_number
  149. else:
  150. update_store_number = out_store_number-sum(v)
  151. k.out_store_number = update_store_number
  152. k.un_out_store_number = k.total_main_unit_number - update_store_number
  153. check_out_store_rewrite_order(self,1)
  154. #销售出库生成销售账单
  155. def get_setting_flow(self):
  156. res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'out_store_2_account_default')
  157. return res
  158. def create_sale_account(self,flow):
  159. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  160. bill_value = {
  161. 'source_model_id': bill_model_id,
  162. 'source_bill_id': self.id,
  163. 'customer_id': self.customer_id and self.customer_id.id,
  164. 'store_id': self.store_id and self.store_id.id,
  165. 'salesmen_id': self.staff_id and self.staff_id.id,
  166. 'company_id': self.company_id and self.company_id.id,
  167. 'department_id': self.department_id and self.department_id.id,
  168. 'sale_type_id': self.sale_type_id and self.sale_type_id.id,
  169. 'subordinate_customer_id': self.subordinate_customer_id and self.subordinate_customer_id.id,
  170. 'carrier_id': self.carrier_id and self.carrier_id.id,
  171. 'car_no': self.car_no,
  172. 'remark_transfer': self.transfer_remark,
  173. 'driver_tel': self.driver_tel,
  174. }
  175. bill = self.env['jc_supply_chain.sale_account'].sudo().create([bill_value])
  176. if self.detail:
  177. detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id
  178. bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number,
  179. 'second_unit_number': i.second_unit_number,
  180. 'goods_id': i.goods_id.id,
  181. 'source_model_id': detail_model_id,
  182. 'source_bill_id': i.id,
  183. 'out_store_number': i.main_unit_number,
  184. 'origin_price': i.origin_price,
  185. 'freight_price': i.freight_price,
  186. 'freight_money': i.freight_money,
  187. 'self_freight_price': i.self_freight_price,
  188. 'self_freight_money': i.self_freight_money,
  189. 'net_price': i.net_price,
  190. 'net_sales': i.net_sales,
  191. 'remark': i.remark,
  192. 'price': i.price,
  193. 'money_without_discount': i.money_without_discount,
  194. 'price_before_discount': i.price_before_discount,
  195. 'discount': i.discount,
  196. }] for i in self.detail]})
  197. if flow.get('create_type',False)=='20':
  198. bill.check()
  199. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  200. self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id)
  201. flow=get_setting_flow(self)
  202. if flow.get('create_type',False) !='1':
  203. create_sale_account(self,flow)
  204. """,
  205. 'code4': """
  206. #如果有已审核的销售账单不允许撤销销售出库
  207. def check_sale_out_store(self,method_name):
  208. rec_name=[]
  209. bill_ids=[]
  210. for rec in self:
  211. model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model
  212. generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False
  213. if generate_bill_id:
  214. res = self.env[model_name].search([('id', 'in', generate_bill_id)])
  215. if res:
  216. for _b in res:
  217. if _b.bill_state>='10':
  218. rec_name.append(_b.name)
  219. else:
  220. bill_ids.append(str(_b.id))
  221. _b.unlink()
  222. else:
  223. res.unlink()
  224. generate_bill=''
  225. generate_model_id=False
  226. if rec_name:
  227. raise ValidationError('存在生成的已审核的销售账单--{}--不允许{}'.format(','.join(rec_name), method_name))
  228. if bill_ids:
  229. generate_bill=rec.generate_bill_id.split(',')
  230. rec.remark= generate_bill
  231. for d in bill_ids:
  232. generate_bill.remove(d)
  233. rec.generate_bill_id= generate_bill
  234. rec.generate_model_id=False
  235. check_sale_out_store(self,'撤销')
  236. #销售出库撤销反写订单
  237. from collections import defaultdict
  238. def check_out_store_rewrite_order(self, flag):
  239. res_dict=defaultdict(list)
  240. if self.sale_order_id:
  241. order_bill = self.env['jc_supply_chain.sale_order'].browse(self.sale_order_id.id)
  242. out_store_number = order_bill.out_store_number
  243. if flag==1:
  244. update_store_number = self.total_main_unit_number + out_store_number
  245. else:
  246. update_store_number = out_store_number -self.total_main_unit_number
  247. order_bill.out_store_number = update_store_number
  248. order_bill.un_out_store_number = order_bill.total_main_unit_number - update_store_number
  249. if self.generate_bill:
  250. for rec in self.detail:
  251. res_dict[rec.order_bill_id].append(rec.main_unit_number)
  252. for k,v in res_dict.items():
  253. out_store_number = k.out_store_number
  254. if flag == 1:
  255. update_store_number = sum(v) + out_store_number
  256. else:
  257. update_store_number = out_store_number-sum(v)
  258. k.out_store_number = update_store_number
  259. k.un_out_store_number = k.total_main_unit_number - update_store_number
  260. check_out_store_rewrite_order(self,2)
  261. """,
  262. 'code5': """
  263. """,
  264. },
  265. 'jc_supply_chain.sale_account': {
  266. 'code': '',
  267. 'code1': common_code1,
  268. 'code2': common_code2,
  269. 'code3': """
  270. #销售账单生成销售发票
  271. def get_invoice_setting_flow(self):
  272. res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'sale_account_2_sale_invoice_default')
  273. return res
  274. def create_sale_invoice(self,flow,):
  275. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  276. bill_value = {
  277. 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None,
  278. 'salesmen_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None,
  279. 'invoice_type_id': self.invoice_type_id.id if hasattr(self, 'invoice_type_id') else None,
  280. 'tax_bill_date': self.tax_bill_date if hasattr(self, 'tax_bill_date') else None,
  281. 'invoice_no': self.invoice_no if hasattr(self, 'invoice_no') else None,
  282. 'bank_account_id': self.bank_account_id.id if hasattr(self, 'bank_account_id') else None,
  283. 'bank_id': self.bank_id.id if hasattr(self, 'bank_id') else None,
  284. 'invoicing_object': self.invoicing_object if hasattr(self, 'invoicing_object') else None,
  285. 'contact_unit_id': self.contact_unit_id.id if hasattr(self, 'contact_unit_id') else None,
  286. 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None,
  287. 'company_id': self.company_id.id if hasattr(self, 'company_id') else None,
  288. 'department_id': self.department_id.id if hasattr(self, 'department_id') else None,
  289. 'sale_type_id': self.sale_type_id.id if hasattr(self, 'sale_type_id') else None,
  290. 'invoice_total_money': self.invoice_total_money if hasattr(self, 'invoice_total_money') else None,
  291. 'car_no': self.car_no if hasattr(self, 'car_no') else None,
  292. 'driver_tel': self.driver_tel if hasattr(self, 'driver_tel') else None,
  293. 'remark_transfer': self.remark_transfer if hasattr(self, 'remark_transfer') else None,
  294. 'carrier_id': self.carrier_id.id if hasattr(self, 'carrier_id') else None,
  295. 'source_bill_id': self.id,
  296. 'source_model_id': bill_model_id,
  297. }
  298. bill = self.env['jc_supply_chain.sale_invoice'].sudo().create([bill_value])
  299. if self.detail:
  300. detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_account_detail')]).id
  301. bill.write({'invoice_detail': [[0, 0, {
  302. 'source_bill_type': '3',
  303. 'source_bill_id': self.id,
  304. 'source_detail_id': i.id,
  305. 'goods_invoice': i.goods_invoice if hasattr(i, 'goods_invoice') else None,
  306. 'transfer_price': i.freight_price if hasattr(i, 'frei') else None,
  307. 'transfer_money': i.freight_money if hasattr(i, 'freight_money') else None,
  308. 'tax_rate': i.tax_rate if hasattr(i, 'tax_rate') else None,
  309. 'tax_money': i.tax_money if hasattr(i, 'tax_money') else None,
  310. 'without_tax_money': i.without_tax_money if hasattr(i, 'without_tax_money') else None,
  311. 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None,
  312. 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None,
  313. 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None,
  314. 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None,
  315. 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None,
  316. 'price': i.price if hasattr(i, 'price') else None,
  317. 'money': i.money if hasattr(i, 'money') else None,
  318. }] for i in self.detail]})
  319. bill.write({'bill_detail': [[0, 0, {
  320. 'source_bill_type': '3',
  321. 'source_bill_id': self.id,
  322. 'source_detail_id': i.id,
  323. 'bill_name': i.goods_id.name,
  324. 'date': i.date if hasattr(i, 'date') else None,
  325. 'store_id': i.store_id.id if hasattr(i, 'store_id') else None,
  326. 'main_unit_number_invoiced': i.main_unit_number_invoiced if hasattr(i, 'main_unit_number_invoiced') else None,
  327. 'main_unit_number_invoicing': i.main_unit_number_invoicing if hasattr(i, 'main_unit_number_invoicing') else None,
  328. 'money_invoiced': i.money_invoiced if hasattr(i, 'money_invoiced') else None,
  329. 'money_invoicing': i.money_invoicing if hasattr(i, 'money_invoicing') else None,
  330. 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None,
  331. 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None,
  332. 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None,
  333. 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None,
  334. 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None,
  335. 'price': i.price if hasattr(i, 'price') else None,
  336. 'money': i.money if hasattr(i, 'money') else None,
  337. 'remark': i.remark if hasattr(i, 'remark') else None,
  338. }] for i in self.detail]})
  339. if flow.get('create_type',False)=='20':
  340. bill.check()
  341. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  342. self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id)
  343. flow=get_invoice_setting_flow(self)
  344. if flow.get('create_type',False) !='1':
  345. create_sale_invoice(self,flow)
  346. # 销售账单生成收款单
  347. def get_receipt_setting_flow(self):
  348. res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'sale_account_2_sale_receipt_default')
  349. return res
  350. def create_sale_receipt(self,flow):
  351. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  352. bill_value = {
  353. 'company_id':flow.get('company_id',False) ,
  354. 'department_id': self.department_id.id if hasattr(self, 'department_id') else None,
  355. 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None,
  356. 'receipt_type_id': flow.get('receipt_type_id',False),
  357. 'salesmen_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None,
  358. 'receipt_account_id': flow.get('receipt_account_id',False) ,
  359. 'receipt_account': self.receipt_account if hasattr(self, 'receipt_account') else None,
  360. 'incoming_account_id': self.incoming_account_id.id if hasattr(self, 'incoming_account_id') else None,
  361. 'incoming_account': self.incoming_account if hasattr(self, 'incoming_account') else None,
  362. 'money': self.total_money if hasattr(self, 'total_money') else None,
  363. 'contact_unit_id': self.contact_unit_id.id if hasattr(self, 'contact_unit_id') else None,
  364. 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None,
  365. 'source_bill_id': self.id,
  366. 'source_model_id': bill_model_id,
  367. }
  368. bill = self.env['jc_supply_chain.sale_receipt'].sudo().create([bill_value])
  369. if flow.get('create_type',False)=='20':
  370. bill.check()
  371. self.generate_model2_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  372. self.generate_bill2_id=(self.generate_bill2_id+','+str(bill.id)) if self.generate_bill2_id else str(bill.id)
  373. flow=get_receipt_setting_flow(self)
  374. if flow.get('create_type',False) !='1':
  375. create_sale_receipt(self,flow)
  376. """,
  377. 'code4': """
  378. #有生成的销售发票和销售收款单不允许撤销
  379. def uncheck_bill(self,method_name):
  380. def check_sale_out_store(self,method_name,flag):
  381. rec_name=[]
  382. bill_ids=[]
  383. for rec in self:
  384. if flag==1:
  385. model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model
  386. generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False
  387. else:
  388. model_name=self.env['ir.model'].sudo().browse(self.generate_model2_id.id).model
  389. generate_bill_id=[int(i) for i in rec.generate_bill2_id.split(',')] if rec.generate_bill2_id else False
  390. if generate_bill_id:
  391. res = self.env[model_name].search([('id', 'in', generate_bill_id)])
  392. if res:
  393. for _b in res:
  394. if _b.bill_state>='10':
  395. rec_name.append(_b.name)
  396. else:
  397. bill_ids.append(str(_b.id))
  398. _b.unlink()
  399. else:
  400. res.unlink()
  401. generate_bill=''
  402. generate_model_id=False
  403. if rec_name:
  404. if flag==1:
  405. raise ValidationError('存在生成的已审核的销售发票--{}--不允许{}'.format(','.join(rec_name), method_name))
  406. else:
  407. raise ValidationError('存在生成的已审核的销售收款--{}--不允许{}'.format(','.join(rec_name), method_name))
  408. if bill_ids:
  409. if flag ==1:
  410. generate_bill=rec.generate_bill_id.split(',')
  411. else:
  412. generate_bill=rec.generate_bill2_id.split(',')
  413. for d in bill_ids:
  414. generate_bill.remove(d)
  415. if flag==1:
  416. rec.generate_bill_id= generate_bill
  417. rec.generate_model_id=False
  418. else:
  419. rec.generate_bill2_id= generate_bill
  420. rec.generate_model2_id=False
  421. check_sale_out_store(self,method_name,1)
  422. check_sale_out_store(self,method_name,2)
  423. uncheck_bill(self,'撤销')
  424. """,
  425. 'code5': """
  426. """,
  427. },
  428. 'jc_supply_chain.sale_chargeback': {
  429. 'code': '',
  430. 'code1': common_code1,
  431. 'code2': common_code2,
  432. 'code3': """
  433. #销售退单生成退库
  434. def get_invoice_setting_flow(self):
  435. res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'return_bill_2_return_store_default')
  436. return res
  437. def create_return_store(self,flow,):
  438. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  439. bill_value = {
  440. 'company_id': self.company_id.id if hasattr(self, 'company_id') else None,
  441. 'department_id': self.department_id.id if hasattr(self, 'department_id') else None,
  442. 'date': self.date if hasattr(self, 'date') else None,
  443. 'customer_id': self.customer_id.id if hasattr(self, 'customer_id') else None,
  444. 'staff_id': self.salesmen_id.id if hasattr(self, 'salesmen_id') else None,
  445. 'store_id': self.store_id.id if hasattr(self, 'store_id') else None,
  446. 'sale_type_id': self.sale_type_id.id if hasattr(self, 'sale_type_id') else None,
  447. 'provider_id': self.provider_id.id if hasattr(self, 'provider_id') else None,
  448. 'subordinate_customer_id': self.subordinate_customer_id.id if hasattr(self, 'subordinate_customer_id') else None,
  449. 'car_no': self.car_no if hasattr(self, 'car_no') else None,
  450. 'carrier_id': self.carrier_id.id if hasattr(self, 'carrier_id') else None,
  451. 'transfer_remark': self.transfer_remark if hasattr(self, 'transfer_remark') else None,
  452. 'driver_tel': self.driver_tel if hasattr(self, 'driver_tel') else None,
  453. 'source_bill_id': self.id,
  454. 'source_model_id': bill_model_id,
  455. }
  456. bill = self.env['jc_supply_chain.sale_return_store'].sudo().create([bill_value])
  457. if self.detail:
  458. detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_account_detail')]).id
  459. bill.write({'detail': [[0, 0, {
  460. 'source_bill_type': '9',
  461. 'source_bill_id': self.id,
  462. 'source_detail_id': i.id,
  463. 'goods_place_id': i.goods_place_id.id if hasattr(i, 'goods_place_id') else None,
  464. 'goods_batch_id': i.goods_batch_id.id if hasattr(i, 'goods_batch_id') else None,
  465. 'remark': i.remark if hasattr(i, 'remark') else None,
  466. 'cost_price': i.cost_price if hasattr(i, 'cost_price') else None,
  467. 'cost_money': i.cost_money if hasattr(i, 'cost_money') else None,
  468. 'goods_id': i.goods_id.id if hasattr(i, 'goods_id') else None,
  469. 'main_unit_number': i.main_unit_number if hasattr(i, 'main_unit_number') else None,
  470. 'second_unit_number': i.second_unit_number if hasattr(i, 'second_unit_number') else None,
  471. 'main_unit_id': i.main_unit_id.id if hasattr(i, 'main_unit_id') else None,
  472. 'second_unit_id': i.second_unit_id.id if hasattr(i, 'second_unit_id') else None,
  473. 'price': i.price if hasattr(i, 'price') else None,
  474. 'money': i.money if hasattr(i, 'money') else None,}] for i in self.detail]})
  475. if flow.get('create_type',False)=='20':
  476. bill.check()
  477. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  478. self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id)
  479. flow=get_invoice_setting_flow(self)
  480. if flow.get('create_type',False) !='1':
  481. create_return_store(self,flow)
  482. """,
  483. 'code4': """
  484. #如果有已审核的销售退库单不允许撤销
  485. def check_sale_out_store(self,method_name):
  486. rec_name=[]
  487. bill_ids=[]
  488. for rec in self:
  489. model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model
  490. generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False
  491. if generate_bill_id:
  492. res = self.env[model_name].search([('id', 'in', generate_bill_id)])
  493. if res:
  494. for _b in res:
  495. if _b.bill_state>='10':
  496. rec_name.append(_b.name)
  497. else:
  498. bill_ids.append(str(_b.id))
  499. _b.unlink()
  500. else:
  501. res.unlink()
  502. generate_bill=''
  503. generate_model_id=False
  504. if rec_name:
  505. raise ValidationError('存在生成的已审核的销售退库--{}--不允许{}'.format(','.join(rec_name), method_name))
  506. if bill_ids:
  507. generate_bill=rec.generate_bill_id.split(',')
  508. rec.remark= generate_bill
  509. for d in bill_ids:
  510. generate_bill.remove(d)
  511. rec.generate_bill_id= generate_bill
  512. rec.generate_model_id=False
  513. check_sale_out_store(self,'撤销')
  514. """,
  515. 'code5': """
  516. """,
  517. },
  518. 'jc_supply_chain.sale_return_store': {
  519. 'code': '',
  520. 'code1': common_code1,
  521. 'code2': common_code2,
  522. 'code3': """
  523. #销售退库单生成销售账单
  524. def get_setting_flow(self):
  525. res = self.env['setting_center.sale_type'].query_create_type(self.sale_type_id.id,'return_store_2_return_invoice_default')
  526. return res
  527. def create_sale_account(self,flow):
  528. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  529. bill_value = {
  530. 'source_model_id': bill_model_id,
  531. 'source_bill_id': self.id,
  532. 'customer_id': self.customer_id and self.customer_id.id,
  533. 'store_id': self.store_id and self.store_id.id,
  534. 'salesmen_id': self.staff_id and self.staff_id.id,
  535. 'company_id': self.company_id and self.company_id.id,
  536. 'department_id': self.department_id and self.department_id.id,
  537. 'sale_type_id': self.sale_type_id and self.sale_type_id.id,
  538. 'subordinate_customer_id': self.subordinate_customer_id and self.subordinate_customer_id.id,
  539. 'carrier_id': self.carrier_id and self.carrier_id.id,
  540. 'car_no': self.car_no,
  541. 'remark_transfer': self.transfer_remark,
  542. 'driver_tel': self.driver_tel,
  543. }
  544. bill = self.env['jc_supply_chain.sale_account'].sudo().create([bill_value])
  545. if self.detail:
  546. detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id
  547. bill.write({'detail': [[0, 0, {'main_unit_number': i.main_unit_number*-1,
  548. 'second_unit_number': i.second_unit_number*-1,
  549. 'goods_id': i.goods_id.id,
  550. 'source_bill_type': '5',
  551. 'source_bill_id': self.id,
  552. 'source_detail_id': i.id,
  553. 'out_store_number': i.main_unit_number,
  554. 'origin_price': i.origin_price if hasattr(i,'orgin_price') else None,
  555. 'freight_price': i.freight_price,
  556. 'freight_money': i.freight_money,
  557. 'self_freight_price': i.self_freight_price,
  558. 'self_freight_money': i.self_freight_money,
  559. 'net_price': i.net_price,
  560. 'net_sales': i.net_sales,
  561. 'remark': i.remark,
  562. 'price': i.price,
  563. 'money_without_discount': i.money_without_discount,
  564. 'price_before_discount': i.price_before_discount,
  565. 'discount': i.discount,
  566. }] for i in self.detail]})
  567. if flow.get('create_type',False)=='20':
  568. bill.check()
  569. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  570. self.generate_bill_id=(self.generate_bill_id+','+str(bill.id)) if self.generate_bill_id else str(bill.id)
  571. flow=get_setting_flow(self)
  572. if flow.get('create_type',False) !='1':
  573. create_sale_account(self,flow)
  574. """,
  575. 'code4': """
  576. #如果有已审核的销售账单不允许撤销
  577. def check_sale_out_store(self,method_name):
  578. rec_name=[]
  579. bill_ids=[]
  580. for rec in self:
  581. model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model
  582. generate_bill_id=[int(i) for i in rec.generate_bill_id.split(',')] if rec.generate_bill_id else False
  583. if generate_bill_id:
  584. res = self.env[model_name].search([('id', 'in', generate_bill_id)])
  585. if res:
  586. for _b in res:
  587. if _b.bill_state>='10':+
  588. rec_name.append(_b.name)
  589. else:
  590. bill_ids.append(str(_b.id))
  591. _b.unlink()
  592. else:
  593. res.unlink()
  594. generate_bill=''
  595. generate_model_id=False
  596. if rec_name:
  597. raise ValidationError('存在生成的已审核的销售账单--{}--不允许{}'.format(','.join(rec_name), method_name))
  598. if bill_ids:
  599. generate_bill=rec.generate_bill_id.split(',')
  600. rec.remark= generate_bill
  601. for d in bill_ids:
  602. generate_bill.remove(d)
  603. rec.generate_bill_id= generate_bill
  604. rec.generate_model_id=False
  605. check_sale_out_store(self,'撤销')
  606. """,
  607. 'code5': """
  608. """,
  609. },
  610. 'jc_supply_chain.transfer_out_store': {
  611. 'code': '',
  612. 'code1': common_code1,
  613. 'code2': common_code2,
  614. 'code3': """
  615. #调拨出库生成调拨入库
  616. def get_setting_flow(self):
  617. res = self.env['setting_center.transfer_type'].query_create_type(self.transfer_type_id.id,'transfer_out_2_in_type_default')
  618. return res
  619. def create_transfer_in_store(self,flow):
  620. bill_model_id = self.env['ir.model'].search([('model', '=', self._name)]).id
  621. bill_value = {
  622. 'source_model_id': bill_model_id,
  623. 'source_bill_id': self.id,
  624. 'in_store_id': self.in_store_id.id,
  625. 'out_store_id': self.out_store_id.id,
  626. 'transfer_type_id': self.transfer_type_id.id,
  627. 'department_id': self.department_id.id,
  628. 'company_id': self.company_id.id,
  629. }
  630. bill = self.env['jc_supply_chain.transfer_in_store'].sudo().create([bill_value])
  631. if self.detail:
  632. detail_model_id = self.env['ir.model'].search([('model', '=', 'jc_supply_chain.sale_out_store_detail')]).id
  633. bill.write({'detail': [[0, 0, {
  634. 'source_bill_type': '23',
  635. 'source_bill_id': self.id,
  636. 'source_detail_id': _.id,
  637. 'goods_id': _.goods_id.id,
  638. 'main_unit_number': _.main_unit_number,
  639. 'second_unit_number': _.second_unit_number,
  640. 'price': _.price,
  641. 'cost_price': _.cost_price,
  642. 'freight_price': _.freight_price,
  643. 'goods_place_id': _.goods_place_id.id,
  644. 'goods_batch_id': _.goods_batch_id.id,
  645. }] for _ in self.detail]})
  646. if flow.get('create_type',False)=='20':
  647. bill.check()
  648. self.generate_model_id=self.env['ir.model'].sudo().search([('model','=',bill._name)]).id
  649. self.generate_bill_id=bill.id
  650. flow=get_setting_flow(self)
  651. if flow.get('create_type',False) !='1':
  652. create_transfer_in_store(self,flow)
  653. """,
  654. 'code4': """
  655. #如果有已审核的调拨入库单不允许撤销
  656. def logic_sale_return_store(self):
  657. if self.generate_bill_id:
  658. model_name=self.env['ir.model'].sudo().browse(self.generate_model_id.id).model
  659. bill=self.env[model_name].sudo().search([('id','=',self.generate_bill_id)])
  660. if bill.bill_state=='10' or bill.bill_state =='20':
  661. raise ValidationError('存在已审核或已完毕的调拨入库单--{}--不允许撤销当前调拨出库单'.format(bill.name))
  662. else:
  663. bill.sudo().unlink()
  664. self.generate_bill_id=0
  665. self.generate_model_id=False
  666. logic_sale_return_store(self)
  667. """,
  668. 'code5': """
  669. """,
  670. },
  671. }