Skip to content

Commit

Permalink
[FIX]入库单、发货单及其他出入库单不能审批就可以审核问题
Browse files Browse the repository at this point in the history
  • Loading branch information
floraXiao committed Jun 26, 2018
1 parent 3699452 commit 54ca9eb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
24 changes: 15 additions & 9 deletions buy/models/buy_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def unlink(self):

@api.one
def _wrong_receipt_done(self):
if self.state == 'done':
raise UserError(u'请不要重复入库')
batch_one_list_wh = []
batch_one_list = []
for line in self.line_in_ids:
Expand Down Expand Up @@ -389,7 +391,8 @@ def buy_receipt_done(self):
invoice_id = self._receipt_make_invoice()
self.write({
'voucher_id': voucher and voucher.id,
'invoice_id': invoice_id and invoice_id.id,# 为保证审批流程顺畅,否则,未审批就可审核
'invoice_id': invoice_id and invoice_id.id,
'state': 'done', # 为保证审批流程顺畅,否则,未审批就可审核
})
# 采购费用产生结算单
self._buy_amount_to_invoice()
Expand All @@ -409,6 +412,8 @@ def buy_receipt_done(self):
@api.one
def buy_receipt_draft(self):
'''反审核采购入库单/退货单,更新本单的付款状态/退款状态,并删除生成的结算单、付款单及凭证'''
if self.state == 'draft':
raise UserError(u'请不要重复撤销')
# 查找产生的付款单
source_line = self.env['source.order.line'].search(
[('name', '=', self.invoice_id.id)])
Expand All @@ -432,15 +437,22 @@ def buy_receipt_draft(self):
[('name', '=', self.invoice_id.name)])
invoice_ids.money_invoice_draft()
invoice_ids.unlink()
# 反审核采购入库单时删除对应的入库凭证
voucher = self.voucher_id
if voucher.state == 'done':
voucher.voucher_draft()
voucher.unlink()
# 如果存在分单,则将差错修改中置为 True,再次审核时不生成分单
self.write({
'modifying': False,
'state': 'draft',
})
receipt_ids = self.search(
[('order_id', '=', self.order_id.id)])
receipt_ids = self.order_id and self.search(
[('order_id', '=', self.order_id.id)]) or []
if len(receipt_ids) > 1:
self.write({
'modifying': True,
'state': 'draft',
})
# 修改订单行中已执行数量
if self.order_id:
Expand All @@ -454,12 +466,6 @@ def buy_receipt_draft(self):
# 调用wh.move中反审核方法,更新审核人和审核状态
self.buy_move_id.cancel_approved_order()

# 反审核采购入库单时删除对应的入库凭证
voucher, self.voucher_id = self.voucher_id, False
if voucher.state == 'done':
voucher.voucher_draft()
voucher.unlink()

@api.one
def buy_share_cost(self):
'''入库单上的采购费用分摊到入库单明细行上'''
Expand Down
2 changes: 1 addition & 1 deletion money/wizard/partner_statements_wizard_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<button name='partner_statements_without_goods' string='不带商品明细的对账单'
attrs="{'invisible': [('is_doc','!=',False)]}" type='object' class='oe_highlight'/>
<button name='partner_statements_with_goods' string='带商品明细的对账单' type='object' class='oe_highlight'/>
or
或者
<button string='取消' class='oe_link' special='cancel'/>
</footer>
</form>
Expand Down
24 changes: 16 additions & 8 deletions sell/models/sell_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def goods_inventory(self, vals):
@api.one
def _wrong_delivery_done(self):
'''审核时不合法的给出报错'''
if self.state == 'done':
raise UserError(u'请不要重复发货')
for line in self.line_in_ids:
if line.goods_qty <= 0 or line.price_taxed < 0:
raise UserError(u'商品 %s 的数量和商品含税单价不能小于0!' % line.goods_id.name)
Expand Down Expand Up @@ -448,7 +450,8 @@ def sell_delivery_done(self):
invoice_id = record._delivery_make_invoice()
record.write({
'voucher_id': voucher and voucher.id,
'invoice_id': invoice_id and invoice_id.id,# 为保证审批流程顺畅,否则,未审批就可审核
'invoice_id': invoice_id and invoice_id.id,
'state': 'done', # 为保证审批流程顺畅,否则,未审批就可审核
})
# 销售费用产生结算单
record._sell_amount_to_invoice()
Expand All @@ -475,6 +478,8 @@ def sell_delivery_done(self):
@api.one
def sell_delivery_draft(self):
'''反审核销售发货单/退货单,更新本单的收款状态/退款状态,并删除生成的结算单、收款单及凭证'''
if self.state == 'draft':
raise UserError(u'请不要重复撤销')
# 查找产生的收款单
source_line = self.env['source.order.line'].search(
[('name', '=', self.invoice_id.id)])
Expand Down Expand Up @@ -503,15 +508,22 @@ def sell_delivery_draft(self):
raise UserError(u'发货单已核销,不能撤销发货!')
invoice_ids.money_invoice_draft()
invoice_ids.unlink()
# 删除产生的出库凭证
voucher = self.voucher_id
if voucher and voucher.state == 'done':
voucher.voucher_draft()
voucher.unlink()
# 如果存在分单,则将差错修改中置为 True,再次审核时不生成分单
self.write({
'modifying': False,
'state': 'draft',
})
delivery_ids = self.search(
[('order_id', '=', self.order_id.id)])
delivery_ids = self.order_id and self.search(
[('order_id', '=', self.order_id.id)]) or []
if len(delivery_ids) > 1:
self.write({
'modifying': True,
'state': 'draft',
})
# 将原始订单中已执行数量清零
if self.order_id:
Expand All @@ -525,11 +537,7 @@ def sell_delivery_draft(self):
# 调用wh.move中反审核方法,更新审核人和审核状态
self.sell_move_id.cancel_approved_order()

# 删除产生的出库凭证
voucher, self.voucher_id = self.voucher_id, False
if voucher and voucher.state == 'done':
voucher.voucher_draft()
voucher.unlink()
return True

@api.multi
def sell_to_return(self):
Expand Down
6 changes: 0 additions & 6 deletions warehouse/models/warehouse_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ def approve_order(self):
:return:
"""
for order in self:
if order.state == 'done':
raise UserError(u'请不要重复确认')
order.prev_approve_order()
order.line_out_ids.action_done()
order.line_in_ids.action_done()
Expand All @@ -350,7 +348,6 @@ def approve_order(self):
return self.write({
'approve_uid': self.env.uid,
'approve_date': fields.Datetime.now(self),
'state': 'done',
})

def prev_cancel_approved_order(self):
Expand All @@ -363,16 +360,13 @@ def cancel_approved_order(self):
:return:
"""
for order in self:
if order.state == 'draft':
raise UserError(u'请不要重复撤销')
order.prev_cancel_approved_order()
order.line_out_ids.action_draft()
order.line_in_ids.action_draft()

return self.write({
'approve_uid': False,
'approve_date': False,
'state': 'draft',
})

@api.multi
Expand Down
35 changes: 29 additions & 6 deletions warehouse/models/warehouse_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from utils import inherits, inherits_after, create_name, create_origin
import odoo.addons.decimal_precision as dp
from odoo import models, fields, api
from odoo.exceptions import UserError


class WhOut(models.Model):
Expand Down Expand Up @@ -35,13 +36,22 @@ class WhOut(models.Model):
@api.multi
@inherits_after()
def approve_order(self):
self.create_voucher()
if self.state == 'done':
raise UserError(u'请不要重复出库')
voucher = self.create_voucher()
self.write({
'voucher_id': voucher and voucher[0].id,
'state': 'done',
})
return True

@api.multi
@inherits()
def cancel_approved_order(self):
if self.state == 'draft':
raise UserError(u'请不要重复撤销')
self.delete_voucher()
self.state = 'draft'
return True

@api.multi
Expand Down Expand Up @@ -110,7 +120,6 @@ def create_voucher(self):
'debit': credit_sum,
'voucher_id': voucher.id,
})
self.voucher_id = voucher
if len(self.voucher_id.line_ids) > 0:
self.voucher_id.voucher_done()
else:
Expand All @@ -120,7 +129,7 @@ def create_voucher(self):
@api.one
def delete_voucher(self):
# 反审核其他出库单时删除对应的出库凭证
voucher, self.voucher_id = self.voucher_id, False
voucher = self.voucher_id
if voucher.state == 'done':
voucher.voucher_draft()

Expand Down Expand Up @@ -158,13 +167,22 @@ class WhIn(models.Model):
@api.multi
@inherits()
def approve_order(self):
self.create_voucher()
if self.state == 'done':
raise UserError(u'请不要重复入库')
voucher = self.create_voucher()
self.write({
'voucher_id': voucher and voucher[0].id,
'state': 'done',
})
return True

@api.multi
@inherits()
def cancel_approved_order(self):
if self.state == 'draft':
raise UserError(u'请不要重复撤销')
self.delete_voucher()
self.state = 'draft'
return True

@api.multi
Expand Down Expand Up @@ -211,7 +229,6 @@ def create_voucher(self):
'ref': '%s,%s' % (self._name, self.id)})
else:
vouch_id = self.env['voucher'].create({'date': self.date, 'ref': '%s,%s' % (self._name, self.id)})
self.voucher_id = vouch_id
debit_sum = 0
for line in self.line_in_ids:
init_obj = self.is_init and 'init_warehouse - %s' % (self.id) or ''
Expand Down Expand Up @@ -253,7 +270,7 @@ def delete_voucher(self):
if self.voucher_id:
if self.voucher_id.state == 'done':
self.voucher_id.voucher_draft()
voucher, self.voucher_id = self.voucher_id, False
voucher = self.voucher_id
# 始初化单反审核只删除明细行
if self.is_init:
vouch_obj = self.env['voucher'].search(
Expand Down Expand Up @@ -299,16 +316,22 @@ def goods_inventory(self, vals):
@api.multi
@inherits()
def approve_order(self):
if self.state == 'done':
raise UserError(u'请不要重复入库')
if self.env.user.company_id.is_enable_negative_stock:
result_vals = self.env['wh.move'].create_zero_wh_in(
self, self._name)
if result_vals:
return result_vals
self.state = 'done'
return True

@api.multi
@inherits()
def cancel_approved_order(self):
if self.state == 'draft':
raise UserError(u'请不要重复撤销')
self.state = 'draft'
return True

@api.multi
Expand Down

0 comments on commit 54ca9eb

Please sign in to comment.