Skip to content

Commit

Permalink
Merge pull request #24 from osbzr/master
Browse files Browse the repository at this point in the history
180712
  • Loading branch information
lonelyleaves committed Jul 12, 2018
2 parents 21e8540 + 8a322d9 commit c8dc433
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 54 deletions.
9 changes: 1 addition & 8 deletions buy/models/buy_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _compute_all_amount(self):
self.amount = total - self.discount_amount + self.delivery_fee

@api.one
@api.depends('is_return', 'invoice_id.reconciled', 'invoice_id.amount', 'order_id.paid_amount', 'amount')
@api.depends('is_return', 'invoice_id.reconciled', 'invoice_id.amount')
def _get_buy_money_state(self):
'''返回付款状态'''
if not self.is_return:
Expand All @@ -45,13 +45,6 @@ def _get_buy_money_state(self):
self.money_state = u'部分付款'
elif self.invoice_id.reconciled == self.invoice_id.amount:
self.money_state = u'全部付款'
if not self.invoice_by_receipt and self.order_id: # 购货订单按收货结算时
if self.order_id.paid_amount == 0:
self.money_state = u'未付款'
elif self.order_id.paid_amount < self.amount:
self.money_state = u'部分付款'
elif self.order_id.paid_amount == self.amount:
self.money_state = u'全部付款'

# 返回退款状态
if self.is_return:
Expand Down
6 changes: 6 additions & 0 deletions buy/tests/test_buy_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ def test_action_view_receipt(self):
receipt.buy_receipt_done()
self.order.action_view_receipt()

def test_buy_order_done_no_attribute(self):
'''检查属性是否填充'''
self.order.line_ids[0].attribute_id = False
with self.assertRaises(UserError):
self.order.buy_order_done()


class TestBuyOrderLine(TransactionCase):

Expand Down
2 changes: 0 additions & 2 deletions goods_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 上海开阖软件 ((http:www.osbzr.com).)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
2 changes: 1 addition & 1 deletion goods_code/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2018 上海开阖软件 ((http:www.osbzr.com).)
# Copyright 2018 上海开阖软件 ((http://www.osbzr.com).)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
Expand Down
2 changes: 0 additions & 2 deletions goods_code/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 上海开阖软件 ((http:www.osbzr.com).)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import goods
2 changes: 0 additions & 2 deletions goods_code/models/goods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2018 上海开阖软件 ((http:www.osbzr.com).)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields

Expand Down
18 changes: 16 additions & 2 deletions money/models/money_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,20 @@ def _get_or_pay(self, line, business_type,
to_invoice_id.to_reconcile = 0
to_invoice_id.reconciled = -line.this_reconcile

# 应收冲应付,应收行、应付行分别生成负的结算单,并且核销
if business_type in ['get_to_pay']:
if not float_is_zero(line.this_reconcile, 2):
invoice_id = self.env['money.invoice'].create({
'name': name,
'category_id': line.category_id.id,
'amount': -line.this_reconcile,
'date': self.date,
'date_due': line.date_due,
'partner_id': partner_id.id,
})
# 核销 业务伙伴 的本次核销金额
invoice_id.to_reconcile = 0
invoice_id.reconciled = -line.this_reconcile
return True

@api.multi
Expand Down Expand Up @@ -1136,8 +1150,8 @@ def _get_or_pay_cancel(self, line, business_type, name):
line.name.to_reconcile += line.this_reconcile
line.name.reconciled -= line.this_reconcile

# 应收转应收、应付转应付,找到生成的结算单反审核并删除
if business_type in ['get_to_get', 'pay_to_pay']:
# 应收转应收、应付转应付、应收冲应付,找到生成的结算单反审核并删除
if business_type in ['get_to_get', 'pay_to_pay', 'get_to_pay']:
invoices = self.env['money.invoice'].search([('name', '=', name)])
for inv in invoices:
if inv.state == 'done':
Expand Down
50 changes: 21 additions & 29 deletions money/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def _init_source_create(self, name, partner_id, category_id, is_init, date,

@api.one
def _set_receivable_init(self):
# 如果有前期初值,删掉已前的单据
money_invoice_id = self.env['money.invoice'].search([
('partner_id', '=', self.id),
('is_init', '=', True)])
if money_invoice_id:
money_invoice_id.money_invoice_draft()
money_invoice_id.unlink()
if self.receivable_init:
# 如果有前期初值,删掉已前的单据
money_invoice_id = self.env['money.invoice'].search([
('partner_id', '=', self.id),
('is_init', '=', True)])
if money_invoice_id:
money_invoice_id.money_invoice_draft()
money_invoice_id.unlink()
# 创建结算单
categ = self.env.ref('money.core_category_sale')
self._init_source_create("期初应收余额", self.id, categ.id, True,
Expand All @@ -44,14 +44,14 @@ def _set_receivable_init(self):

@api.one
def _set_payable_init(self):
# 如果有前期初值,删掉已前的单据
money_invoice_id = self.env['money.invoice'].search([
('partner_id', '=', self.id),
('is_init', '=', True)])
if money_invoice_id:
money_invoice_id.money_invoice_draft()
money_invoice_id.unlink()
if self.payable_init:
# 如果有前期初值,删掉已前的单据
money_invoice_id = self.env['money.invoice'].search([
('partner_id', '=', self.id),
('is_init', '=', True)])
if money_invoice_id:
money_invoice_id.money_invoice_draft()
money_invoice_id.unlink()
# 创建结算单
categ = self.env.ref('money.core_category_purchase')
self._init_source_create("期初应付余额", self.id, categ.id, True,
Expand Down Expand Up @@ -110,14 +110,14 @@ def _set_init_balance(self):
start_date_period_id = self.env['finance.period'].search_period(start_date)
if self.init_balance and start_date_period_id.is_closed:
raise UserError(u'初始化期间(%s)已结账!' % start_date_period_id.name)
# 如果有前期初值,删掉已前的单据
other_money_id = self.env['other.money.order'].search([
('bank_id', '=', self.id),
('is_init', '=', True)])
if other_money_id:
other_money_id.other_money_draft()
other_money_id.unlink()
if self.init_balance:
# 如果有前期初值,删掉已前的单据
other_money_id = self.env['other.money.order'].search([
('bank_id', '=', self.id),
('is_init', '=', True)])
if other_money_id:
other_money_id.other_money_draft()
other_money_id.unlink()
# 资金期初 生成 其他收入
other_money_init = self.with_context(type='other_get').env['other.money.order'].create({
'bank_id': self.id,
Expand All @@ -134,14 +134,6 @@ def _set_init_balance(self):
})
# 审核 其他收入单
other_money_init.other_money_done()
else:
other_money_id = self.env['other.money.order'].search([
('bank_id', '=', self.id),
('is_init', '=', True)])
if other_money_id:
other_money_id.other_money_draft()
other_money_id.unlink()
self.balance = 0


init_balance = fields.Float(u'期初',
Expand Down
8 changes: 3 additions & 5 deletions sell/models/sell_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,12 @@ def create_voucher(self):
line_ids = self.is_return and self.line_in_ids or self.line_out_ids
for line in line_ids: # 发货单/退货单明细
cost = self.is_return and -line.cost or line.cost

if cost: # 贷方明细
if not cost:
continue # 缺货审核发货单时不产生出库凭证
else: # 贷方明细
sum_amount += cost
self._create_voucher_line(line.goods_id.category_id.account_id,
0, cost, voucher, line.goods_id, line.goods_qty)
else:
# 缺货审核发货单时不产生出库凭证
continue
if sum_amount: # 借方明细
self._create_voucher_line(self.sell_move_id.finance_category_id.account_id,
sum_amount, 0, voucher, False, 0)
Expand Down
12 changes: 12 additions & 0 deletions sell/tests/test_sell_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ def test_sell_adjust_done_goods_done(self):
with self.assertRaises(UserError):
adjust.sell_adjust_done()

def test_sell_adjust_done_no_attribute(self):
'''检查属性是否填充'''
adjust = self.env['sell.adjust'].create({
'order_id': self.order.id,
'line_ids': [(0, 0, {'goods_id': self.keyboard.id,
'quantity': 3.0,
}),
]
})
with self.assertRaises(UserError):
adjust.sell_adjust_done()


class TestSellAdjustLine(TransactionCase):

Expand Down
5 changes: 5 additions & 0 deletions sell/tests/test_sell_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ def test_sell_delivery_done_currency(self):
self.delivery.currency_id = self.env.ref('base.USD')
self.delivery.sell_delivery_done()

def test_sell_delivery_draft_twice(self):
'''重复撤销报错'''
with self.assertRaises(UserError):
self.delivery.sell_delivery_draft()


class TestWhMoveLine(TransactionCase):

Expand Down
6 changes: 6 additions & 0 deletions sell/tests/test_sell_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def test_action_view_return(self):
self.return_order.action_view_return()
self.assertTrue(self.return_order.return_count == 2)

def test_sell_order_done_no_attribute(self):
'''检查属性是否填充'''
self.order.line_ids[0].goods_id = self.env.ref('goods.keyboard')
with self.assertRaises(UserError):
self.order.sell_order_done()


class TestSellOrderLine(TransactionCase):

Expand Down
2 changes: 2 additions & 0 deletions sell_to_buy/models/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class buy_order(models.Model):

sell_id = fields.Many2one('sell.order', u'销货订单', index=True,
readonly=True,
copy=False,
ondelete='restrict',
help=u'关联的销货订单')

Expand All @@ -29,6 +30,7 @@ class buy_order_line(models.Model):

sell_line_id = fields.Many2one('sell.order.line',
u'销货单行',
copy=False,
ondelete='restrict',
help=u'对应的销货订单行')

Expand Down
2 changes: 1 addition & 1 deletion sell_to_buy/models/sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
class sell_order_line(models.Model):
_inherit = "sell.order.line"

is_bought = fields.Boolean(u'已采购')
is_bought = fields.Boolean(u'已采购', copy=False, readonly=True)
3 changes: 3 additions & 0 deletions sell_to_buy/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
import test_buy
import test_wizard
24 changes: 24 additions & 0 deletions sell_to_buy/tests/test_buy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase


class TestBuy(TransactionCase):

def setUp(self):
super(TestBuy, self).setUp()
self.order = self.env.ref('buy.buy_order_1')
self.sell_order = self.env.ref('sell.sell_order_1')

def test_sell_to_buy(self):
'''根据销货订单生成购货订单'''
res = self.order.sell_to_buy()
self.assertEqual(res['res_model'], 'sell.to.buy.wizard')

def test_buy_order_line_unlink(self):
'''删除购货订单行时,如果对应销货订单行已采购,则去掉打勾'''
wizard = self.env['sell.to.buy.wizard'].with_context({'active_id': self.order.id}).create(
{'sell_line_ids': [(6, 0, [self.sell_order.line_ids.ids])]})
wizard.button_ok()
for line in self.order.line_ids:
if line.sell_line_id:
line.unlink()
37 changes: 37 additions & 0 deletions sell_to_buy/tests/test_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class TestSellToBuyWizard(TransactionCase):

def setUp(self):
super(TestSellToBuyWizard, self).setUp()
self.order = self.env.ref('buy.buy_order_1')
self.sell_order = self.env.ref('sell.sell_order_1')
self.sell_line_1 = self.env.ref('sell.sell_order_line_1')
self.sell_line_1.copy()
self.wizard = self.env['sell.to.buy.wizard'].with_context({'active_id': self.order.id}).create({'sell_line_ids': [(6, 0, [self.sell_order.line_ids.ids])]})


def test_button_ok(self):
'''生成按钮,复制销货订单行到购货订单中'''
self.wizard.button_ok()
self.assertEqual(len(self.order.line_ids), 3)
self.assertEqual(self.order.sell_id, self.sell_order)
for line in self.sell_order.line_ids:
self.assertTrue(line.is_bought)

def test_button_ok_select_two_sell_order(self):
'''一次只能勾选同一张销货订单的行'''
order_2 = self.env.ref('sell.sell_order_2')
lines = self.sell_order.line_ids + order_2.line_ids
self.wizard.write({'sell_line_ids': [(6, 0, [lines.ids])]})
with self.assertRaises(UserError):
self.wizard.button_ok()

def test_button_ok_no_sell_line_ids(self):
'''销货订单行不能为空'''
wizard = self.env['sell.to.buy.wizard'].with_context({'active_id': self.order.id}).create({'sell_line_ids': []})
with self.assertRaises(UserError):
wizard.button_ok()
4 changes: 2 additions & 2 deletions sell_to_buy/views/buy_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name='inherit_id' ref='buy.buy_order_form'/>
<field name="arch" type="xml">
<button name="buy_order_done" position="after">
<button name="sell_to_buy" string="根据销货生成购货" type="object"
<button name="sell_to_buy" string="参照销货订单" type="object"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('sell_id', '!=', False)]}" class="oe_highlight"/>
</button>
<field name="currency_id" position="after">
Expand All @@ -23,7 +23,7 @@
<field name='inherit_id' ref='sell.sell_order_form' />
<field name="arch" type="xml">
<field name="using_attribute" position="after" >
<field name="is_bought" invisible="1"/>
<field name="is_bought"/>
</field>
</field>
</record>
Expand Down
2 changes: 2 additions & 0 deletions sell_to_buy/wizard/sell_to_buy_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _get_vals(self, order, line):
def button_ok(self):
'''生成按钮,复制销货订单行到购货订单中'''
for wizard in self:
if not wizard.sell_line_ids:
raise UserError(u'销货订单行不能为空')
active_id = self.env.context.get('active_id')
buy_lines = []
order_dict = {} # 用来判断勾选行是否来自同一张销货订单
Expand Down

0 comments on commit c8dc433

Please sign in to comment.