Skip to content

Commit

Permalink
Merge pull request #1870 from Judystudy/master
Browse files Browse the repository at this point in the history
[IMP] 完善相关逻辑,出库时可以选择出库库位;库存余额表优化;代码优化
  • Loading branch information
GoodERPJeff committed Jul 10, 2018
2 parents fe74be0 + 02ae686 commit 43a840d
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 25 deletions.
8 changes: 7 additions & 1 deletion buy/views/buy_receipt_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@
attrs="{'required': [('using_attribute','=', True)], 'readonly': [('using_attribute','!=', True)],}"/>
<field name='lot' groups='goods.batch_groups'
attrs="{'readonly': [('using_batch', '=', False)], 'required': [('using_batch', '=', True)]}"/>
<field name='location_id' groups="warehouse.multi_location_groups" options="{'no_open': True, 'no_create': True}" domain="['&amp;',('warehouse_id', '=', parent.warehouse_dest_id),'|',('goods_id', '=', goods_id),('goods_id', '=', False)]"/>
<field name='location_id' groups="warehouse.multi_location_groups"
options="{'no_open': True, 'no_create': True}"
domain="['&amp;',('warehouse_id', '=', parent.warehouse_dest_id),'|',('goods_id', '=', goods_id),('goods_id', '=', False)]"/>
<field name="goods_uos_qty" sum="合计辅助数量"
groups="goods.auxiliary_unit_groups"/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down Expand Up @@ -296,6 +298,10 @@
domain="[('goods_id', '=', goods_id), ('state', '=', 'done'), ('lot', '!=', False), ('qty_remaining', '>', 0), ('warehouse_dest_id', '=', parent.warehouse_id)]"
context="{'lot': True}" options="{'no_open': True, 'no_create': True}"
groups='goods.batch_groups'/>
<field name="location_id"
groups="warehouse.multi_location_groups"
options="{'no_open': True, 'no_create': True}"
domain="[('warehouse_id','=',parent.warehouse_id),('goods_id', '=', goods_id)]"/>
<field name="goods_uos_qty" sum="合计辅助数量"
groups="goods.auxiliary_unit_groups"/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
45 changes: 32 additions & 13 deletions finance/tests/test_finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_voucher_done_costs_types_in(self):
})]
})
voucher.voucher_done()

def test_restricted_account(self):
''' 测试受限的记账科目 '''
account_debit = self.env.ref('finance.small_business_chart1801')
Expand Down Expand Up @@ -224,6 +224,7 @@ def test_default_voucher_date_last(self):
"default_voucher_date": "last", })

setting_row.execute()
self.env['ir.values'].set_default('finance.config.settings', 'default_voucher_date', 'last')
voucher_obj._default_voucher_date()
voucher_obj.create({})

Expand Down Expand Up @@ -348,6 +349,11 @@ def test_name_search(self):

self.assertEqual(result, real_result)

# 搜索输入的是编号 code 1001
result1 = self.env['finance.account'].name_search('1001')
real_result1 = [(self.cash.id, self.cash.code + ' ' + self.cash.name)]
self.assertEqual(result1, real_result1)

def test_get_smallest_code_account(self):
account = self.env['finance.account']
account.get_smallest_code_account()
Expand Down Expand Up @@ -380,28 +386,30 @@ def test_write(self):
''' 测试删除科目 '''
# 界面上修改预设科目报错
with self.assertRaises(UserError):
self.cash.with_context({'modify_from_webclient':1}).write({'source':'1'})
# 界面上记过账科目不能删除
self.cash.source = 'init'
self.cash.with_context({'modify_from_webclient': 1}).write({'source': 'init'})
# 界面上记过账科目不能修改
account_bank = self.env.ref('finance.account_bank')
with self.assertRaises(UserError):
self.env.ref('finance.account_bank').source = ''
self.env.ref('finance.account_bank').with_context({'modify_from_webclient':1}).unlink()
account_bank.source = ''
account_bank.with_context({'modify_from_webclient': 1}).write({'source': 'init'})
def test_add_child(self):
''' 测试增加子科目 '''
# 末级科目增加子科目
self.cash.button_add_child()
income = self.env.ref('finance.account_income')
wizard = self.env['wizard.account.add.child'].with_context(
{'active_id':self.cash.id}
{'active_id': income.id}
).create({
'account_code':'01',
'account_name':'纸币',
'account_code': '01',
'account_name': '纸币',
})
wizard.create_account()
#非末级科目增加子科目
# 非末级科目增加子科目
wizard = self.env['wizard.account.add.child'].with_context(
{'active_id':self.env.ref('finance.small_business_chart1701').id}
).create({
'account_code':'01',
'account_name':'',
{'active_id':self.env.ref('finance.small_business_chart1701').id}).create({
'account_code': '08',
'account_name': '',
})
wizard.create_account()
# 修改下级编码
Expand All @@ -414,6 +422,17 @@ def test_add_child(self):
wizard.account_code = '021'
wizard._onchange_account_code()

# 选择的科目层级已经是最低层级科目了,不能建立在它下面建立下级科目! 报错
self.env['ir.values'].set_default('finance.config.settings', 'default_account_hierarchy_level', '2')
business_chart170108 = self.env['finance.account'].search([('code', '=', '170108')])
with self.assertRaises(UserError):
wizard = self.env['wizard.account.add.child'].with_context({'active_id': business_chart170108.id}). \
create({
'account_code': '01',
'account_name': 'test'
})
wizard.create_account()

def test_add_child_multi(self):
with self.assertRaises(UserError):
wizard = self.env['wizard.account.add.child'].with_context(
Expand Down
15 changes: 15 additions & 0 deletions finance/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,21 @@ def test_recreate_voucher_name(self):
self.checkout_voucher.voucher_done()
wizard.button_checkout()

def test_recreate_voucher_name(self):
''' Test: recreate_voucher_name 按年重排 '''
wizard = self.env['checkout.wizard'].create(
{'date': '2015-12-31'})
settings = self.env['finance.config.settings'].create({'default_reset_period': 'year',
'default_auto_reset': True,
'default_reset_init_number': 2})
settings.execute()
self.env['ir.values'].set_default('finance.config.settings', 'default_reset_period', 'year')
settings.default_reset_period = 'year'
settings.default_auto_reset = True
wizard.period_id = self.env.ref('finance.period_201512')
self.voucher_15_12.voucher_done()
self.checkout_voucher.voucher_done()
wizard.button_checkout()

class TestActionReportPickingWrapped(TransactionCase):
def test_action_report(self):
Expand Down
4 changes: 4 additions & 0 deletions sell/views/sell_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@
domain="[('goods_id', '=', goods_id), ('state', '=', 'done'), ('lot', '!=', False), ('qty_remaining', '>', 0), ('warehouse_dest_id', '=', parent.warehouse_id)]"
context="{'lot': True}" options="{'no_open': True, 'no_create': True}"
groups='goods.batch_groups'/>
<field name="location_id"
options="{'no_open':True,'no_create':True}"
groups="warehouse.multi_location_groups"
domain="[('warehouse_id','=',parent.warehouse_id),('goods_id','=',goods_id)]"/>
<field name='goods_uos_qty' sum='辅助数量合计'
groups='goods.auxiliary_unit_groups'/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
8 changes: 6 additions & 2 deletions warehouse/models/goods.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def get_matching_records_by_lot(self, lot_id, qty, uos_qty=0, suggested=False):
'expiration_date': lot_id.expiration_date}], \
lot_id.get_real_cost_unit() * qty

def get_matching_records(self, warehouse, qty, uos_qty=0,
attribute=None, ignore_stock=False, ignore=None):
def get_matching_records(self, warehouse, qty, uos_qty=0, attribute=None,
ignore_stock=False, ignore=None, move_line=False):
"""
获取匹配记录,不考虑批号
:param ignore_stock: 当参数指定为True的时候,此时忽略库存警告
Expand Down Expand Up @@ -153,6 +153,10 @@ def get_matching_records(self, warehouse, qty, uos_qty=0,
domain.append(
('location_id', '=', self.env.context.get('location')))

# 出库单行 填写了库位
if not self.env.context.get('location') and move_line and move_line.location_id:
domain.append(('location_id', '=', move_line.location_id.id))

# TODO @zzx需要在大量数据的情况下评估一下速度
# 出库顺序按 库位 就近、先到期先出、先进先出
lines = self.env['wh.move.line'].search(
Expand Down
10 changes: 7 additions & 3 deletions warehouse/models/move_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def create_matching_obj(self, line, matching):
)

def prev_action_done(self):
"""
发货 matching
"""
for line in self:
if line.warehouse_id.type == 'stock' and \
line.goods_id.is_using_matching():
Expand All @@ -101,9 +104,10 @@ def prev_action_done(self):
else:
matching_records, cost = line.goods_id \
.get_matching_records(
line.warehouse_id, line.goods_qty,
uos_qty=line.goods_uos_qty,
attribute=line.attribute_id)
line.warehouse_id, line.goods_qty,
uos_qty = line.goods_uos_qty,
attribute = line.attribute_id,
move_line = line)
for matching in matching_records:
self.create_matching_obj(line, matching)
line.cost_unit = safe_division(cost, line.goods_qty)
Expand Down
3 changes: 1 addition & 2 deletions warehouse/report/stock_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ def init(self):
LEFT JOIN attribute attribute on attribute.id = line.attribute_id
LEFT JOIN uom uom ON goods.uom_id = uom.id
LEFT JOIN uom uos ON goods.uos_id = uos.id
LEFT JOIN location loc ON loc.goods_id = line.goods_id
LEFT JOIN location loc ON loc.id = line.location_id
WHERE wh.type = 'stock'
AND line.state = 'done'
AND line.qty_remaining != 0
AND ( goods.no_stock is null or goods.no_stock = FALSE)
AND line.qty_remaining != 0
GROUP BY wh.name, line.lot, attribute.name, goods.name, goods.id, goods.brand, loc.name, uom.name, uos.name
Expand Down
1 change: 1 addition & 0 deletions warehouse/report/stock_balance_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<field name='goods' />
<field name='attribute_id' groups='goods.multi_attrs_groups' />
<field name='lot' groups='goods.batch_groups' />
<field name="location" groups="warehouse.multi_location_groups"/>
<field name='uom' />
<field name='uos' groups='goods.auxiliary_unit_groups' />
<field name='warehouse' groups='warehouse.multi_warehouse_groups' />
Expand Down
4 changes: 4 additions & 0 deletions warehouse/view/warehouse_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@
domain="[('goods_id', '=', goods_id), ('state', '=', 'done'), ('lot', '!=', False), ('qty_remaining', '>', 0), ('warehouse_dest_id', '=', parent.warehouse_id)]"
context="{'lot': True}"
options="{'no_open': True, 'no_create': True}" />
<field name="location_id"
options="{'no_open':True,'no_create':True}"
groups="warehouse.multi_location_groups"
domain="[('warehouse_id','=',parent.warehouse_id),('goods_id', '=', goods_id)]"/>
<field name='goods_uos_qty' sum='1'
groups='goods.auxiliary_unit_groups'/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
5 changes: 1 addition & 4 deletions warehouse_wave/models/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def create_wave_reserved(self, wave_row, line):

@api.multi
def get_sell_delivery(self, goods_id, attribute_id):
''' 查找缺货发货单 '''
''' 查找缺货发货单 '''
sell_delivery_lists = []
for active_model in self.env[self.active_model].browse(self.env.context.get('active_ids')):
for line in active_model.line_out_ids:
Expand All @@ -215,7 +215,6 @@ def get_sell_delivery(self, goods_id, attribute_id):

return sell_delivery_lists


@api.multi
def create_wave(self):
"""
Expand Down Expand Up @@ -275,8 +274,6 @@ def create_wave(self):
active_model.wave_id = wave_row.id
express_type = active_model.express_type

# eeee

# 所有订单都不缺货
wave_row.express_type = express_type
wave_row.line_ids = self.build_wave_line_data(
Expand Down

0 comments on commit 43a840d

Please sign in to comment.