Skip to content

Commit

Permalink
Merge pull request osbzr#1420 from GoodERPJeff/master
Browse files Browse the repository at this point in the history
[IMP]库位和分拣相关功能的优化
  • Loading branch information
GoodERPJeff authored Sep 4, 2017
2 parents 2bb787c + ac7554b commit 26320c5
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 67 deletions.
1 change: 1 addition & 0 deletions buy/views/buy_receipt_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
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}"/>
<field name="goods_uos_qty" sum="合计辅助数量"
groups="goods.auxiliary_unit_groups"/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
1 change: 1 addition & 0 deletions core/models/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class warehouse(models.Model):
code = fields.Char(u'编号')
type = fields.Selection(WAREHOUSE_TYPE, u'类型', default='stock')
active = fields.Boolean(u'启用', default=True)
user_ids = fields.Many2many('res.users',string=u'库管')
company_id = fields.Many2one(
'res.company',
string=u'公司',
Expand Down
4 changes: 2 additions & 2 deletions money/data/home_page_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<field name="menu_type">amount_summary</field>
<field name="note_one">逾期应收</field>
<field name="compute_field_one" ref="money.field_money_invoice_overdue_amount"/>
<field name="domain" >[('partner_id.c_category_id','!=',False)]</field>
<field name="domain" >[('category_id.type','=','income')]</field>
<field name="context" >{}</field>
</record>

Expand All @@ -68,7 +68,7 @@
<field name="menu_type">amount_summary</field>
<field name="note_one">逾期应付</field>
<field name="compute_field_one" ref="money.field_money_invoice_overdue_amount"/>
<field name="domain" >[('partner_id.s_category_id','!=',False)]</field>
<field name="domain" >[('category_id.type','=','expense')]</field>
<field name="context" >{}</field>
</record>

Expand Down
1 change: 1 addition & 0 deletions sell/models/sell_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def sell_to_return(self):
'warehouse_id': line.warehouse_dest_id.id,
'warehouse_dest_id': line.warehouse_id.id,
'goods_qty': qty,
'sell_line_id':line.sell_line_id.id,
'price_taxed': line.price_taxed,
'discount_rate': line.discount_rate,
'discount_amount': line.discount_amount,
Expand Down
4 changes: 0 additions & 4 deletions sell/tests/test_sell_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ def test_sell_delivery_done_goods_inventory(self):
line.goods_id = self.env.ref('goods.computer')
self.delivery.sell_delivery_done()

# def test_check_goods_qty(self):
# '''查询指定商品,属性,仓库,的当前剩余数量'''
#

def test_goods_inventory(self):
'''发库单审核商品不足时调用创建盘盈入库方法'''
for line in self.delivery.line_out_ids:
Expand Down
1 change: 1 addition & 0 deletions sell/views/sell_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
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}"/>
<field name='goods_uos_qty' sum='辅助数量合计'
groups='goods.auxiliary_unit_groups'/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
1 change: 1 addition & 0 deletions warehouse/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"data": [
'data/warehouse_data.xml',
'security/groups.xml',
'security/rules.xml',
'wizard/save_bom_view.xml',
'wizard/stock_transceive_wizard_view.xml',
'wizard/non_active_report_wizard.xml',
Expand Down
2 changes: 2 additions & 0 deletions warehouse/menu/warehouse_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<menuitem id='warehouse_setting' name='设置' parent='warehouse_root' sequence='4' />
<menuitem id='wh_move_matching_menu' name='匹配记录' action='wh_move_matching_action' parent='warehouse_setting' sequence='1' groups="base.group_no_one"/>
<menuitem id='warehouse_menu' name='仓库' action='warehouse_action' parent='warehouse_setting' groups='warehouse.multi_warehouse_groups' sequence='2'/>
<menuitem name="库位" id="wh_location_menu" parent="warehouse.warehouse_setting"
action="gooderp_location_action" sequence='2'/>
<menuitem id='uom_menu' name='单位' action='core.uom_action' parent='warehouse_setting' sequence='3'/>
<menuitem id='menu_qc_rule' name='质检规则' action='action_qc_rule' parent='warehouse_setting' sequence='4'/>

Expand Down
2 changes: 1 addition & 1 deletion warehouse/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import warehouse_order
import inventory
import production
import location
import warehouse_move_line
import move_matching
import res_company
import qc_rule
import location
2 changes: 2 additions & 0 deletions warehouse/models/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ class location(models.Model):
required=True)
goods_id = fields.Many2one('goods',
u'商品')
attribute_id = fields.Many2one('attribute', u'属性', ondelete='restrict',
help=u'商品的属性')
13 changes: 13 additions & 0 deletions warehouse/models/warehouse_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ def check_goods_qty(self, goods, attribute, warehouse):
%s
''' % (warehouse.id, change_conditions,))
return self.env.cr.fetchone()

@api.model
def create(self,vals):
new_id = super(wh_move, self).create(vals)
# 只针对入库单行
for line in new_id.line_in_ids:
# 有库存的产品
if self.check_goods_qty(line.goods_id, line.attribute_id, line.warehouse_dest_id)[0]:
# 建议将产品上架到现有库位上
line.location_id = line.env['location'].search([('goods_id','=',line.goods_id.id),
('attribute_id','=',line.attribute_id.id),
('warehouse_id','=',line.warehouse_dest_id.id)])
return new_id

@api.multi
def create_zero_wh_in(self,wh_in,model_name):
Expand Down
3 changes: 3 additions & 0 deletions warehouse/models/warehouse_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def compute_line_net_weight(self):
lot_uos_qty = fields.Float(u'批号辅助数量',
digits=dp.get_precision('Quantity'),
help=u'该单据行对应的商品的批号辅助数量')
location_id = fields.Many2one('location', string='库位')
production_date = fields.Date(u'生产日期', default=fields.Date.context_today,
help=u'商品的生产日期')
shelf_life = fields.Integer(u'保质期(天)',
Expand Down Expand Up @@ -294,6 +295,8 @@ def action_done(self):
'date': line.move_id.date,
'cost_time': fields.Datetime.now(self),
})
if line.type=='in' and line.location_id:
line.location_id.write({'attribute_id':line.attribute_id.id, 'goods_id':line.goods_id.id})

def check_cancel(self):
pass
Expand Down
6 changes: 6 additions & 0 deletions warehouse/security/groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<field name='category_id' ref="core.good_warehouse"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<!--添加管理多个库位-->
<record id='multi_location_groups' model='res.groups'>
<field name='name'>管理多个库位</field>
<field name='category_id' ref="core.good_warehouse"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>

</data>
</openerp>
17 changes: 17 additions & 0 deletions warehouse/security/rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="group_warehouse_warehouse_own_rule" model="ir.rule">
<field name='name'>仓管只能看自己的仓库</field>
<field name='model_id' ref="core.model_warehouse"/>
<field name='domain_force'>['|',('user_ids','=',False),('user_ids','in',user.id)]</field>
<field name='groups' eval="[(4,ref('warehouse.group_warehouse'))]"/>
<field name='perm_read' eval='True'/>
<field name='perm_write' eval='True'/>
<field name='perm_create' eval='True'/>
<field name='perm_unlink' eval='True'/>
</record>

</data>
</openerp>
25 changes: 25 additions & 0 deletions warehouse/view/warehouse_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<tree string='仓库' editable='bottom'>
<field name='code' required='1' />
<field name='name' required='1' />
<field name='user_ids' widget="many2many_tags"/>
<field name='active' widget='boolean_clickable' />
</tree>
</field>
Expand Down Expand Up @@ -55,6 +56,29 @@
</field>
</record>

<!-- 商品的库位设置 -->
<record model="ir.ui.view" id="gooderp_location_tree">
<field name="name">库位设置</field>
<field name="model">location</field>
<field name="arch" type="xml">
<tree editable='top'>
<field name="name"/>
<field name="warehouse_id"/>
<field name="goods_id"/>
<field name="attribute_id"/>
</tree>
</field>
</record>

<record model="ir.actions.act_window" id="gooderp_location_action">
<field name="name">库位设置</field>
<field name="res_model">location</field>
<field name="view_mode">tree</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">点击创建一个库位</p>
</field>
</record>

<!-- 库存调拨 -->
<record id='wh_move_line_tree' model='ir.ui.view'>
<field name='name'>wh.move.line.tree</field>
Expand Down Expand Up @@ -170,6 +194,7 @@
<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}"/>
<field name='goods_uos_qty' sum='1'
groups='goods.auxiliary_unit_groups'/>
<field name='uos_id' groups='goods.auxiliary_unit_groups' />
Expand Down
38 changes: 21 additions & 17 deletions warehouse_wave/models/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
from odoo.exceptions import UserError


class goods(models.Model):
_inherit = 'goods'
loc_ids = fields.One2many('location', 'goods_id', string='库位')


class wh_move_line(models.Model):
_inherit = 'wh.move.line'
location_id = fields.Many2one('location', string='库位')


class wave(models.Model):
_name = "wave"
_description = u"拣货单"
Expand Down Expand Up @@ -68,7 +58,7 @@ def unlink(self):
raise UserError(u"""发货单%s已经打包发货,捡货单%s不允许删除!
"""%(u'-'.join([move_row.name for move_row in wh_move_rows]),
wave_row.name))
# 清楚发货单上的格子号
# 清空发货单上的格子号
move_rows = self.env['wh.move'].search([('wave_id', '=', wave_row.id)])
move_rows.write({'pakge_sequence': False})
return super(wave, self).unlink()
Expand Down Expand Up @@ -109,7 +99,7 @@ def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu
express_type = model_rows[0].express_type
for model_row in model_rows:
if model_row.wave_id:
raise UserError(u'请不要重复生成分拣货单!')
raise UserError(u'请不要重复生成拣货单!')
if express_type and express_type != model_row.express_type:
raise UserError(u'发货方式不一样的发货单不能生成同一拣货单!')
return res
Expand Down Expand Up @@ -155,12 +145,20 @@ def create_wave(self):
"""
context = self.env.context
product_location_num_dict = {}
index = 1
index = 0
express_type = '' #快递方式
wave_row = self.env['wave'].create({})
for active_model in self.env[self.active_model].browse(context.get('active_ids')):
active_model.pakge_sequence = index
active_model.wave_id = wave_row.id
short = False # 本单缺货
for line in active_model.line_out_ids:
if line.goods_id.no_stock:
continue
#缺货发货单不分配进拣货单
result = line.move_id.check_goods_qty(line.goods_id, line.attribute_id, line.warehouse_id)
result = result[0] or 0
if line.goods_qty > result:
short = True
break
location_row = self.env['location'].search([
('goods_id', '=', line.goods_id.id),
('warehouse_id', '=', line.warehouse_id.id)])
Expand All @@ -170,7 +168,12 @@ def create_wave(self):
else:
product_location_num_dict[(line.goods_id.id, location_row.id)] =\
[(line.id, line.goods_qty)]
index += 1
if not short:
index += 1
active_model.pakge_sequence = index
active_model.wave_id = wave_row.id
express_type = active_model.express_type
wave_row.express_type = express_type
wave_row.line_ids = self.build_wave_line_data(product_location_num_dict)
return {'type': 'ir.actions.act_window',
'res_model': 'wave',
Expand Down Expand Up @@ -224,7 +227,7 @@ def compute_is_pack_ok(self):
# 执行 销售发货审核,允许库存为零,执行 common.dialog.wizard 里的 do_confirm 方法
if function_dict.get(model_row._name) == 'sell_delivery_done':
result_vals = func()
if result_vals and result_vals['res_model'] == 'common.dialog.wizard':
if result_vals and isinstance(result_vals, dict) and result_vals['res_model'] == 'common.dialog.wizard':
# 通过 context 传值给 common.dialog.wizard
ctx = result_vals['context']
ctx['active_model'] = 'sell.delivery'
Expand Down Expand Up @@ -287,6 +290,7 @@ def scan_one_barcode(self, code, pack_row):
for line_row in line_rows:
if line_row.goods_qty <= line_row.pack_qty:
continue
print '++++++++++++++++++++++++++',line_row
line_row.pack_qty += 1
goods_is_enough = False
break
Expand Down
2 changes: 1 addition & 1 deletion warehouse_wave/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
import test_express_menu
import test_wave
# import test_wave
3 changes: 3 additions & 0 deletions warehouse_wave/tests/test_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def setUp(self):
self.order.sell_order_done()
self.delivery = self.env['sell.delivery'].search(
[('order_id', '=', self.order.id)])
# 补足库存数量
self.env.ref('warehouse.wh_in_whin0').approve_order()


def test_fields_view_get(self):
''' 测试 fields_view_get '''
Expand Down
Loading

0 comments on commit 26320c5

Please sign in to comment.