Skip to content

Commit

Permalink
Merge remote-tracking branch 'osbzr/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert-yuan committed May 19, 2017
2 parents e5450df + dda42cc commit aa1e11e
Show file tree
Hide file tree
Showing 34 changed files with 288 additions and 90 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[【在线试用】](http://demo.gooderp.org:8888)
[【下载Windows绿色版】](http://com.osbzr.net/osbzr_downloads/static/gooderp.zip)
[![在线试用](http://www.gooderp.org/logo.png)](http://demo.gooderp.org:8888/login?db=demo&login=demo&key=demo) 在线试用

----
[![Join the chat at https://gitter.im/osbzr/gooderp](https://badges.gitter.im/osbzr/gooderp.svg)](https://gitter.im/osbzr/gooderp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![License: AGPL-3](https://img.shields.io/badge/licence-AGPL--3-blue.svg)](http://www.gnu.org/licenses/agpl-3.0-standalone.html)
[![Build Status](https://travis-ci.org/osbzr/gooderp_addons.svg?branch=master)](https://travis-ci.org/osbzr/gooderp_addons)
[![Coverage Status](https://coveralls.io/repos/github/osbzr/gooderp_addons/badge.svg?branch=master)](https://coveralls.io/github/osbzr/gooderp_addons?branch=master)
[![Issue Count](https://codeclimate.com/github/osbzr/gooderp_addons/badges/issue_count.svg)](https://codeclimate.com/github/osbzr/gooderp_addons)


开发环境准备
-------------
Expand Down
31 changes: 17 additions & 14 deletions account_cost/models/cost_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,36 @@ def _amount_to_invoice(self):

@api.one
def _create_mv_cost(self):

"""
在所关联的入库单/发货单上创建费用行
:return:
"""
all_amount = sum(wh_move_line.amount for wh_move_line in self.env['wh.move.line'].search([('move_id', 'in', self.wh_move_ids.ids)]))
for mv in self.wh_move_ids:

if mv.origin == 'buy.receipt.buy':
buy_id = self.env['buy.receipt'].search([('buy_move_id', '=', mv.id)])
mv_amount = sum(mv_line.amount for mv_line in mv.line_in_ids)
for cost_line in self.line_ids:
cost_mv_in_id = self.env['cost.line'].create({
'partner_id':self.partner_id.id,
'category_id':cost_line.category_id.id,
'amount':cost_line.amount * (mv_amount / all_amount),
'tax':cost_line.tax_amount *(mv_amount / all_amount),
'buy_id': mv.id
'buy_id': buy_id.id
})
self.wm_ids = [(4, cost_mv_in_id.id)]

if mv.origin == 'sell.delivery.sell':
sell_id = self.env['sell.delivery'].search([('sell_move_id', '=', mv.id)])
mv_amount = sum(mv_line.amount for mv_line in mv.line_out_ids)
for cost_line in self.line_ids:
cost_mv_out_id = self.env['cost.line'].create({
'partner_id':self.partner_id.id,
'category_id':cost_line.category_id.id,
'amount':cost_line.amount * (mv_amount / all_amount),
'tax':cost_line.tax_amount *(mv_amount / all_amount),
'sell_id': mv.id
'sell_id': sell_id.id
})
self.wm_ids = [(4, cost_mv_out_id.id)]

Expand Down Expand Up @@ -219,18 +224,16 @@ def cost_order_draft(self):
if self.state == 'draft':
raise UserError(u'请不要重复反审核!')

if self.wm_ids:
for mv_id in self.wm_ids:
cost_line_id = mv_id
self.wm_ids = [(3, mv_id.id)]
cost_line_id.unlink()
for mv_id in self.wm_ids:
cost_line_id = mv_id
self.wm_ids = [(3, mv_id.id)]
cost_line_id.unlink()

if self.invoice_ids:
for invoice in self.invoice_ids:
invoice_id = invoice
self.invoice_ids = [(3, invoice.id)]
invoice_id.money_invoice_draft()
invoice_id.unlink()
for invoice in self.invoice_ids:
invoice_id = invoice
self.invoice_ids = [(3, invoice.id)]
invoice_id.money_invoice_draft()
invoice_id.unlink()

#查找产生的付款单并反审核,删除
money_order = self.env['money.order'].search(
Expand Down
44 changes: 44 additions & 0 deletions account_cost/tests/test_cost_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def setUp(self):
self.buy_order_1.buy_order_done()
self.receipt = self.env['buy.receipt'].search([('order_id', '=', self.buy_order_1.id)])

self.sell_order_1 = self.env.ref('sell.sell_order_1')
self.sell_order_1.sell_order_done()
self.delivery = self.env['sell.delivery'].search([('order_id', '=', self.sell_order_1.id)])

def test_cost_order_confim(self):
''' 测试 服务订单 审核 '''
# no name
Expand Down Expand Up @@ -55,3 +59,43 @@ def test_cost_order_draft(self):
# 重复反审核
with self.assertRaises(UserError):
self.cost_order_1.cost_order_draft()

def test_unlink(self):
'''删除服务订单'''
# 不能删除审核过的
self.cost_order_1.cost_order_confim()
with self.assertRaises(UserError):
self.cost_order_1.unlink()
# 删除草稿的
self.cost_order_1.cost_order_draft()
self.cost_order_1.unlink()

def test_create_mv_cost(self):
'''在所关联的入库单/发货单上创建费用行'''
# 关联入库单
self.cost_order_1.wh_move_ids = [(4, self.receipt.buy_move_id.id)]
self.cost_order_1.cost_order_confim()

# 关联发货单
self.cost_order_1.cost_order_draft()
self.cost_order_1.wh_move_ids = [(4, self.delivery.sell_move_id.id)]
self.cost_order_1.cost_order_confim()

def test_cost_order_draft_has_prepayment(self):
'''反审核服务订单'''
self.cost_order_1.prepayment = 20
self.cost_order_1.bank_account_id = self.env.ref('core.alipay')
self.cost_order_1.cost_order_confim()
self.cost_order_1.cost_order_draft()


class test_cost_order_line(TransactionCase):

def setUp(self):
super(test_cost_order_line, self).setUp()
self.cost_order_1 = self.env.ref('account_cost.cost_order_1')

def test_compute_all_amount(self):
'''计算价税合计'''
self.cost_order_1.line_ids[0].amount = 100
self.assertAlmostEqual(self.cost_order_1.line_ids[0].subtotal, 110.0)
2 changes: 1 addition & 1 deletion asset/data/asset_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<record id="small_business_chart410101" model='finance.account'>
<field name='code'>410101</field>
<field name='name'>制造费用-折旧费</field>
<field name='costs_types'>out</field>
<field name='costs_types'>cost</field>
<field name='balance_directions'>in</field>
</record>
<record id="small_business_chart530101" model='finance.account'>
Expand Down
2 changes: 1 addition & 1 deletion auto_backup/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
2) Schedule new action(create a new record)
3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under page 'Technical Data'
4) Set other values as per your preference""",
"depends" : [],
"depends" : ['core'],
"data" : ["views/bkp_conf_view.xml",
"security/ir.model.access.csv",
"data/backup_data.xml"],
Expand Down
8 changes: 4 additions & 4 deletions buy/models/buy_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ def _compute_all_amount(self):
@api.one
def _inverse_price(self):
'''由不含税价反算含税价,保存时生效'''
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)
if not self.price_taxed:
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)

@api.onchange('price', 'tax_rate')
def onchange_price(self):
'''当订单行的不含税单价改变时,改变含税单价'''
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)
if not self.price_taxed:
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)

order_id = fields.Many2one('buy.adjust', u'订单编号', index=True,
required=True, ondelete='cascade',
Expand Down Expand Up @@ -239,8 +241,6 @@ def onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的单位、默认仓库、成本价'''
if self.goods_id:
self.uom_id = self.goods_id.uom_id
if not self.goods_id.cost:
raise UserError(u'请先设置商品(%s)的成本!'%self.goods_id.name)
self.price_taxed = self.goods_id.cost

if self.goods_id.tax_rate and self.order_id.order_id.partner_id.tax_rate:
Expand Down
8 changes: 4 additions & 4 deletions buy/models/buy_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,14 @@ def _compute_all_amount(self):
@api.one
def _inverse_price(self):
'''由不含税价反算含税价,保存时生效'''
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)
if not self.price_taxed:
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)

@api.onchange('price', 'tax_rate')
def onchange_price(self):
'''当订单行的不含税单价改变时,改变含税单价'''
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)
if not self.price_taxed:
self.price_taxed = self.price * (1 + self.tax_rate * 0.01)

order_id = fields.Many2one('buy.order',
u'订单编号',
Expand Down Expand Up @@ -629,8 +631,6 @@ def onchange_goods_id(self):
raise UserError(u'请先选择一个供应商!')
if self.goods_id:
self.uom_id = self.goods_id.uom_id
if not self.goods_id.cost:
raise UserError(u'请先设置商品的成本!')
self.price_taxed = self.goods_id.cost
for line in self.goods_id.vendor_ids:
if line.vendor_id == self.order_id.partner_id \
Expand Down
10 changes: 2 additions & 8 deletions buy/models/buy_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def unlink(self):
if receipt.state == 'done':
raise UserError(u'不能删除已审核的单据')

return receipt.buy_move_id.unlink()
receipt.buy_move_id.unlink()

@api.one
def _wrong_receipt_done(self):
Expand Down Expand Up @@ -482,7 +482,7 @@ def buy_to_return(self):
qty = line.goods_qty
if return_goods.get(line.attribute_id.id):
qty = qty - return_goods[line.attribute_id.id]
if qty != 0:
if qty > 0:
dic = {
'goods_id': line.goods_id.id,
'attribute_id': line.attribute_id.id,
Expand All @@ -498,8 +498,6 @@ def buy_to_return(self):
if len(receipt_line) == 0:
raise UserError(u'该订单已全部退货!')

for line in receipt_line:
print line
vals = {'partner_id': self.partner_id.id,
'is_return': True,
'origin_id': self.id,
Expand All @@ -511,7 +509,6 @@ def buy_to_return(self):
'date': (datetime.datetime.now()).strftime(ISODATEFORMAT),
'line_out_ids': [(0, 0, line) for line in receipt_line],
}
print vals
delivery_return = self.with_context(is_return=True).create(vals)
view_id = self.env.ref('buy.buy_return_form').id
name = u'采购退货单'
Expand Down Expand Up @@ -549,9 +546,6 @@ def onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的成本价,以及公司的进项税'''
self.ensure_one()
if self.goods_id:
if not self.goods_id.cost:
raise UserError(u'请先设置商品的成本!')

is_return = self.env.context.get('default_is_return')
# 如果是采购入库单行 或 采购退货单行
if (self.type == 'in' and not is_return) or (self.type == 'out' and is_return):
Expand Down
5 changes: 1 addition & 4 deletions buy/tests/test_buy_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def test_inverse_price(self):
def test_onchange_price(self):
'''当订单行的不含税单价改变时,改变含税单价'''
for line in self.adjust.line_ids:
line.price_taxed = 0
line.price = 10
line.onchange_price()
self.assertAlmostEqual(line.price_taxed, 11.7)
Expand All @@ -245,10 +246,6 @@ def test_onchange_goods_id(self):

# 测试价格是否是商品的成本
self.assertTrue(line.price_taxed == self.cable.cost)
# 测试不设置商品的成本时是否弹出警告
self.cable.cost = 0.0
with self.assertRaises(UserError):
line.onchange_goods_id()

def test_onchange_discount_rate(self):
''' 订单行优惠率改变时,改变优惠金额'''
Expand Down
45 changes: 41 additions & 4 deletions buy/tests/test_buy_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,45 @@ def test_onchange_partner_id(self):
self.env.ref('goods.keyboard').tax_rate = 12
self.order.onchange_partner_id()

def test_compute_receipt_and_invoice(self):
'''计算生成入库单和结算单的个数'''
self.order.buy_order_done()
self.assertTrue(self.order.receipt_count == 1)

self.order.receipt_ids[0].buy_receipt_done()
self.assertTrue(self.order.invoice_count == 1)
self.assertTrue(self.order.invoice_ids == self.order.receipt_ids[0].invoice_id)

def test_action_view_receipt(self):
'''查看生成的入库单'''
# 生成一张入库单
self.order.buy_order_done()
self.order.action_view_receipt()
# 生成两张入库单
self.order.buy_order_draft()
self.order.buy_order_done()
for line in self.order.receipt_ids[0].line_in_ids:
line.goods_qty = 3
self.order.receipt_ids[0].buy_receipt_done()
self.order.action_view_receipt()

def test_action_view_invoice(self):
'''查看生成的结算单'''
# 生成一张入库单,审核后查看结算单
self.order.buy_order_done()
self.order.action_view_invoice()
self.order.receipt_ids[0].buy_receipt_done()
self.order.action_view_invoice()
# 生成两张入库单,都审核后在购货订单上查看结算单
self.order.receipt_ids[0].buy_receipt_draft()
self.order.buy_order_draft()
self.order.buy_order_done()
for line in self.order.receipt_ids[0].line_in_ids:
line.goods_qty = 3
self.order.receipt_ids[0].buy_receipt_done()
self.order.receipt_ids[0].buy_receipt_done()
self.order.action_view_invoice()


class test_buy_order_line(TransactionCase):

Expand Down Expand Up @@ -267,12 +306,14 @@ def test_compute_all_amount_wrong_tax_rate(self):
def test_inverse_price(self):
'''由不含税价反算含税价,保存时生效'''
for line in self.order.line_ids:
line.price_taxed = 0
line.price = 10
self.assertAlmostEqual(line.price_taxed, 11.7)

def test_onchange_price(self):
'''当订单行的不含税单价改变时,改变含税单价'''
for line in self.order.line_ids:
line.price_taxed = 0
line.price = 10
line.onchange_price()
self.assertAlmostEqual(line.price_taxed, 11.7)
Expand All @@ -286,10 +327,6 @@ def test_onchange_goods_id(self):

# 测试价格是否是商品的成本
self.assertTrue(line.price_taxed == self.cable.cost)
# 测试不设置商品的成本时是否弹出警告
self.cable.cost = 0.0
with self.assertRaises(UserError):
line.onchange_goods_id()

def test_onchange_goods_id_tax_rate(self):
''' 测试 修改产品时,购货单行税率变化 '''
Expand Down
27 changes: 17 additions & 10 deletions buy/tests/test_buy_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,23 @@ def test_buy_receipt_done_currency(self):
[('order_id', '=', self.order.id)])
self.receipt.buy_receipt_done()

def test_buy_to_return(self):
'''采购入库单转化为采购退货单'''
self.receipt.line_in_ids[0].copy()
self.receipt.buy_receipt_done()
self.receipt.buy_to_return()
with self.assertRaises(UserError):
self.receipt.buy_to_return()

# 该订单已全部退货,再次点击按钮则报错
return_order = self.env['buy.receipt'].search([
('is_return', '=', True),
('origin_id', '=', self.receipt.id),
])
return_order.buy_receipt_done()
with self.assertRaises(UserError):
self.receipt.buy_to_return()


class test_wh_move_line(TransactionCase):

Expand All @@ -347,21 +364,11 @@ def setUp(self):

def test_onchange_goods_id(self):
'''测试采购模块中商品的onchange,是否会带出单价'''
# 入库单行:修改鼠标成本为0,测试是否报错
for line in self.receipt.line_in_ids:
line.onchange_goods_id()
self.goods_mouse.cost = 0.0
for line in self.receipt.line_in_ids:
line.goods_id = self.goods_mouse.id
with self.assertRaises(UserError):
line.onchange_goods_id()

# 采购退货单行
for line in self.return_receipt.line_out_ids:
line.goods_id.cost = 0.0
with self.assertRaises(UserError):
line.with_context({'default_is_return': True,
'default_partner': self.return_receipt.partner_id.id}).onchange_goods_id()
line.goods_id.cost = 1.0
line.with_context({'default_is_return': True,
'default_partner': self.return_receipt.partner_id.id}).onchange_goods_id()
Expand Down
1 change: 1 addition & 0 deletions buy/views/buy_receipt_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<group>
<field name="date_due" required="1" attrs="{'readonly': [('state','!=','draft')]}"/>
<field name="order_id" readonly="1"/>
<field name='origin_id' readonly='1'/>
<field name='invoice_id' readonly='1'/>
<field name='voucher_id'/>
<field name="return_state" readonly="1"/>
Expand Down
Loading

0 comments on commit aa1e11e

Please sign in to comment.