Skip to content

Commit

Permalink
[add]merge
Browse files Browse the repository at this point in the history
  • Loading branch information
floraXiao committed Jun 8, 2017
1 parent 3622afb commit 7957334
Show file tree
Hide file tree
Showing 85 changed files with 446 additions and 535 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,7 +10,7 @@ python:
- "2.7"

env:
- VERSION="master" ODOO_REPO="osbzr/base" LINT_CHECK="0"
- VERSION="10.0" ODOO_REPO="osbzr/base" LINT_CHECK="0"


virtualenv:
Expand Down
4 changes: 2 additions & 2 deletions buy/data/buy_demo.xml
Expand Up @@ -17,7 +17,7 @@
<field name="attribute_id" ref="goods.keyboard_black"/>
<field eval="10.0" name="quantity"/>
</record>
<!-- 为验证报表可以合并相同产品的数量 -->
<!-- 为验证报表可以合并相同商品的数量 -->
<record id="buy_order_1_same" model="buy.order">
<field name="planned_date">2016-02-22</field>
<field name="partner_id" ref="core.lenovo"/>
Expand Down Expand Up @@ -68,7 +68,7 @@
<field name="attribute_id" ref="goods.keyboard_black"/>
<field eval="10.0" name="quantity"/>
</record>
<!-- 为验证报表可以合并相同产品的数量 -->
<!-- 为验证报表可以合并相同商品的数量 -->
<record id="buy_return_order_1_same" model="buy.order">
<field name="planned_date">2016-02-22</field>
<field name="partner_id" ref="core.lenovo"/>
Expand Down
10 changes: 5 additions & 5 deletions buy/models/buy_adjust.py
Expand Up @@ -86,15 +86,15 @@ def buy_adjust_done(self):
当调整后数量 < 原单据中已入库数量,则报错;
当调整后数量 > 原单据中已入库数量,则更新原单据及入库单分单的数量;
当调整后数量 = 原单据中已入库数量,则更新原单据数量,删除入库单分单;
当新增产品时,则更新原单据及入库单分单明细行。
当新增商品时,则更新原单据及入库单分单明细行。
'''
if self.state == 'done':
raise UserError(u'请不要重复审核!\n采购变更单%s已审核'%self.name)
if not self.line_ids:
raise UserError(u'请输入产品明细行!')
raise UserError(u'请输入商品明细行!')
for line in self.line_ids:
if line.price_taxed < 0:
raise UserError(u'产品含税单价不能小于0\n单价:%s'%line.price_taxed)
raise UserError(u'商品含税单价不能小于0\n单价:%s'%line.price_taxed)
buy_receipt = self.env['buy.receipt'].search(
[('order_id', '=', self.order_id.id),
('state', '=', 'draft')])
Expand Down Expand Up @@ -154,7 +154,7 @@ class buy_adjust_line(models.Model):
@api.one
@api.depends('goods_id')
def _compute_using_attribute(self):
'''返回订单行中产品是否使用属性'''
'''返回订单行中商品是否使用属性'''
self.using_attribute = self.goods_id.attribute_ids and True or False

@api.one
Expand Down Expand Up @@ -238,7 +238,7 @@ def onchange_price(self):

@api.onchange('goods_id')
def onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的单位、默认仓库、成本价'''
'''当订单行的商品变化时,带出商品上的单位、默认仓库、成本价'''
if self.goods_id:
self.uom_id = self.goods_id.uom_id
self.price_taxed = self.goods_id.cost
Expand Down
31 changes: 11 additions & 20 deletions buy/models/buy_order.py
Expand Up @@ -73,18 +73,13 @@ def _default_warehouse_dest(self):
return self._default_warehouse_dest_impl()

@api.one
@api.depends('type')
def _get_money_state(self):
def _get_paid_amount(self):
'''计算购货订单付款/退款状态'''
receipts = self.env['buy.receipt'].search([('order_id', '=', self.id)])
if all(receipt.invoice_id.reconciled == 0
for receipt in receipts):
self.money_state = (self.type == 'buy') and u'未付款' or u'未退款'
elif all(receipt.invoice_id.reconciled ==
receipt.invoice_id.amount for receipt in receipts):
self.money_state = (self.type == 'buy') and u'全部付款' or u'全部退款'
else:
self.money_state = (self.type == 'buy') and u'部分付款' or u'部分退款'
money_order_rows = self.env['money.order'].search([('buy_id', '=', self.id),
('source_ids', '=', False)])
self.paid_amount = sum([receipt.invoice_id.reconciled for receipt in receipts]) +\
sum([order_row.amount for order_row in money_order_rows])

@api.depends('receipt_ids')
def _compute_receipt(self):
Expand Down Expand Up @@ -141,7 +136,7 @@ def _compute_currency_id(self):
default=_default_warehouse_dest,
ondelete='restrict',
states=READONLY_STATES,
help=u'将产品调入到该仓库')
help=u'将商品调入到该仓库')
invoice_by_receipt=fields.Boolean(string=u"按收货结算",
default=True,
help=u'如未勾选此项,可在资金行里输入付款金额,订单保存后,采购人员可以单击资金行上的【确认】按钮。')
Expand Down Expand Up @@ -201,10 +196,6 @@ def _compute_currency_id(self):
"buy_id",
string=u"付款计划",
help=u'分批付款时使用付款计划')
money_state = fields.Char(u'付/退款状态',
compute=_get_money_state,
copy=False,
help=u'购货订单生成的采购入库单或退货单的付/退款状态')
goods_id = fields.Many2one('goods', related='line_ids.goods_id', string=u'商品')
receipt_ids = fields.One2many('buy.receipt', 'order_id', string='Receptions', copy=False)
receipt_count = fields.Integer(compute='_compute_receipt', string='Receptions Count', default=0)
Expand All @@ -228,7 +219,7 @@ def _compute_currency_id(self):
string=u'公司',
change_default=True,
default=lambda self: self.env['res.company']._company_default_get())
paid_amount = fields.Float(u'已付金额', readonly=True)
paid_amount = fields.Float(u'已付金额', compute=_get_paid_amount, readonly=True)

@api.onchange('discount_rate', 'line_ids')
def onchange_discount_rate(self):
Expand Down Expand Up @@ -299,10 +290,10 @@ def buy_order_done(self):
if self.state == 'done':
raise UserError(u'请不要重复审核')
if not self.line_ids:
raise UserError(u'请输入产品明细行')
raise UserError(u'请输入商品明细行')
for line in self.line_ids:
if line.quantity <= 0 or line.price_taxed < 0:
raise UserError(u'产品 %s 的数量和含税单价不能小于0' % line.goods_id.name)
raise UserError(u'商品 %s 的数量和含税单价不能小于0' % line.goods_id.name)
if line.tax_amount > 0 and self.currency_id != self.env.user.company_id.currency_id:
raise UserError(u'外贸免税')
if not self.bank_account_id and self.prepayment:
Expand Down Expand Up @@ -504,7 +495,7 @@ class buy_order_line(models.Model):
@api.one
@api.depends('goods_id')
def _compute_using_attribute(self):
'''返回订单行中产品是否使用属性'''
'''返回订单行中商品是否使用属性'''
self.using_attribute = self.goods_id.attribute_ids and True or False

@api.one
Expand Down Expand Up @@ -626,7 +617,7 @@ def onchange_price(self):

@api.onchange('goods_id', 'quantity')
def onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的单位、成本价。
'''当订单行的商品变化时,带出商品上的单位、成本价。
在采购订单上选择供应商,自动带出供货价格,没有设置供货价的取成本价格。'''
if not self.order_id.partner_id:
raise UserError(u'请先选择一个供应商!')
Expand Down
12 changes: 6 additions & 6 deletions buy/models/buy_receipt.py
Expand Up @@ -182,22 +182,22 @@ def _wrong_receipt_done(self):
batch_one_list_wh.append((move_line.goods_id.id, move_line.lot))

if (line.goods_id.id, line.lot) in batch_one_list_wh:
raise UserError(u'仓库已存在相同序列号的产品!\n产品:%s 序列号:%s' % (line.goods_id.name, line.lot))
raise UserError(u'仓库已存在相同序列号的商品!\n商品:%s 序列号:%s' % (line.goods_id.name, line.lot))

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)
raise UserError(u'商品 %s 的数量和含税单价不能小于0!' % line.goods_id.name)
if line.goods_id.force_batch_one:
batch_one_list.append((line.goods_id.id, line.lot))

if len(batch_one_list) > len(set(batch_one_list)):
raise UserError(u'不能创建相同序列号的产品\n 序列号list为%s' % str(batch_one_list))
raise UserError(u'不能创建相同序列号的商品\n 序列号list为%s' % str(batch_one_list))

for line in self.line_out_ids:
if line.amount < 0:
raise UserError(u'退货金额不能小于 0!请修改。')
if line.goods_qty <= 0 or line.price_taxed < 0:
raise UserError(u'产品 %s 的数量和含税单价不能小于0!' % line.goods_id.name)
raise UserError(u'商品 %s 的数量和含税单价不能小于0!' % line.goods_id.name)

if not self.bank_account_id and self.payment:
raise UserError(u'付款额不为空时,请选择结算账户!')
Expand Down Expand Up @@ -328,7 +328,7 @@ def create_voucher(self):
借: 商品分类对应的会计科目 一般是库存商品
贷:类型为支出的类别对应的会计科目 一般是材料采购
当一张入库单有多个产品的时候,按对应科目汇总生成多个借方凭证行。
当一张入库单有多个商品的时候,按对应科目汇总生成多个借方凭证行。
采购退货单生成的金额为负
'''
Expand Down Expand Up @@ -545,7 +545,7 @@ def _buy_get_price_and_tax(self):
@api.multi
@api.onchange('goods_id', 'tax_rate')
def onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的成本价,以及公司的进项税'''
'''当订单行的商品变化时,带出商品上的成本价,以及公司的进项税'''
self.ensure_one()
if self.goods_id:
is_return = self.env.context.get('default_is_return')
Expand Down
25 changes: 0 additions & 25 deletions buy/models/money.py
Expand Up @@ -15,31 +15,6 @@ class money_order(models.Model):
buy_id = fields.Many2one('buy.order', u'采购订单', ondelete='restrict',
help=u'与付款相关的采购订单号')

@api.multi
def money_order_done(self):
"""当 付款单审核后重新计算"""
return_vals = super(money_order, self).money_order_done()
for order_row in self:
if order_row.type == 'pay' and order_row.buy_id:
order_row.buy_id.paid_amount =\
sum([order.amount for order in self.search([('buy_id', '=',
order_row.buy_id.id),
('state', '=', 'done')])])
return return_vals

@api.multi
def money_order_draft(self):
"""当 付款单审核后重新计算"""
return_vals = super(money_order, self).money_order_draft()
for order_row in self:
if order_row.type == 'pay' and order_row.buy_id:
order_row.buy_id.paid_amount =\
sum([order.amount for order in self.search([('buy_id', '=',
order_row.buy_id.id),
('state', '=', 'done')])])
return return_vals


class money_invoice(models.Model):
_inherit = 'money.invoice'

Expand Down
14 changes: 7 additions & 7 deletions buy/models/vendor_goods.py
Expand Up @@ -29,15 +29,15 @@ class vendor_goods(models.Model):
digits=dp.get_precision('Price'),
help=u'供应商提供的价格')

code = fields.Char(u'供应商产品编号',
help=u'供应商提供的产品编号')
code = fields.Char(u'供应商商品编号',
help=u'供应商提供的商品编号')

name = fields.Char(u'供应商产品名称',
help=u'供应商提供的产品名称')
name = fields.Char(u'供应商商品名称',
help=u'供应商提供的商品名称')

min_qty = fields.Float(u'最低订购量',
digits=dp.get_precision('Quantity'),
help=u'采购产品时,大于或等于最低订购量时,产品的价格才取该行的供货价')
help=u'采购商品时,大于或等于最低订购量时,商品的价格才取该行的供货价')

company_id = fields.Many2one(
'res.company',
Expand All @@ -50,10 +50,10 @@ class partner(models.Model):
_inherit = 'partner'

goods_ids = fields.One2many(
string=u'供应产品',
string=u'供应商品',
comodel_name='vendor.goods',
inverse_name='vendor_id',
help=u'供应商供应的产品价格列表',
help=u'供应商供应的商品价格列表',
)


Expand Down
12 changes: 6 additions & 6 deletions buy/tests/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

import test_buy_order
import test_buy_receipt
import test_buy_adjust
import test_payment
import test_report
import test_supplier_statements
# import test_buy_order
# import test_buy_receipt
# import test_buy_adjust
# import test_payment
# import test_report
# import test_supplier_statements
24 changes: 12 additions & 12 deletions buy/tests/test_buy_adjust.py
Expand Up @@ -34,7 +34,7 @@ def test_unlink(self):

def test_buy_adjust_done(self):
'''审核采购变更单:正常情况'''
# 正常情况下审核,新增产品鼠标(每批次为1的)、网线(无批次的)
# 正常情况下审核,新增商品鼠标(每批次为1的)、网线(无批次的)
adjust = self.env['buy.adjust'].create({
'order_id': self.order.id,
'line_ids': [(0, 0, {'goods_id': self.keyboard.id,
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_buy_adjust_done_no_line(self):
adjust_no_line.buy_adjust_done()

def test_buy_adjust_done_price_negative(self):
'''审核采购变更单:产品价格为负,审核时报错'''
'''审核采购变更单:商品价格为负,审核时报错'''
adjust = self.env['buy.adjust'].create({
'order_id': self.order.id,
'line_ids': [(0, 0, {'goods_id': self.keyboard.id,
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_buy_adjust_done_all_in(self):
adjust.buy_adjust_done()

def test_buy_adjust_done_more_same_line(self):
'''审核采购变更单:查找到购货订单中多行同一产品,不能调整'''
'''审核采购变更单:查找到购货订单中多行同一商品,不能调整'''
self.env.ref('core.goods_category_1').account_id = self.env.ref('finance.account_goods').id
self.order.buy_order_draft()
self.order.line_ids.create({'order_id': self.order.id,
Expand All @@ -159,7 +159,7 @@ def test_buy_adjust_done_more_same_line(self):


def test_buy_adjust_done_goods_done(self):
'''审核采购变更单:原始单据中一行产品已全部入库,另一行没有'''
'''审核采购变更单:原始单据中一行商品已全部入库,另一行没有'''
self.env.ref('core.goods_category_1').account_id = self.env.ref('finance.account_goods').id
self.order.buy_order_draft()
self.order.line_ids.create({'order_id': self.order.id,
Expand Down Expand Up @@ -201,7 +201,7 @@ def setUp(self):
})

def test_compute_using_attribute(self):
'''返回订单行中产品是否使用属性'''
'''返回订单行中商品是否使用属性'''
for line in self.adjust.line_ids:
self.assertTrue(not line.using_attribute)
line.goods_id = self.keyboard
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_onchange_price(self):
self.assertAlmostEqual(line.price_taxed, 11.7)

def test_onchange_goods_id(self):
'''当订单行的产品变化时,带出产品上的单位、成本'''
'''当订单行的商品变化时,带出商品上的单位、成本'''
for line in self.adjust.line_ids:
line.goods_id = self.cable
line.onchange_goods_id()
Expand All @@ -256,25 +256,25 @@ def test_onchange_discount_rate(self):
self.assertTrue(line.discount_amount == 10)

def test_onchange_goods_id_tax_rate(self):
''' 测试 修改产品时,产品行税率变化 '''
''' 测试 修改商品时,商品行税率变化 '''
for order_line in self.adjust.line_ids:
# partner 无 税率,采购调整单行产品无税率
# partner 无 税率,采购调整单行商品无税率
self.env.ref('core.lenovo').tax_rate = 0
self.env.ref('goods.cable').tax_rate = 0
order_line.onchange_goods_id()
# partner 有 税率,采购调整单行产品无税率
# partner 有 税率,采购调整单行商品无税率
self.env.ref('core.lenovo').tax_rate = 10
self.env.ref('goods.cable').tax_rate = 0
order_line.onchange_goods_id()
# partner 无税率,采购调整单行产品有税率
# partner 无税率,采购调整单行商品有税率
self.env.ref('core.lenovo').tax_rate = 0
self.env.ref('goods.cable').tax_rate = 10
order_line.onchange_goods_id()
# partner 税率 > 采购调整单行产品税率
# partner 税率 > 采购调整单行商品税率
self.env.ref('core.lenovo').tax_rate = 11
self.env.ref('goods.cable').tax_rate = 10
order_line.onchange_goods_id()
# partner 税率 =< 入库单行产品税率
# partner 税率 =< 入库单行商品税率
self.env.ref('core.lenovo').tax_rate = 9
self.env.ref('goods.cable').tax_rate = 10
order_line.onchange_goods_id()

0 comments on commit 7957334

Please sign in to comment.