From f587593ec3447ef7b0b313f8b1e2df518ea60e21 Mon Sep 17 00:00:00 2001 From: zxy Date: Tue, 10 Jul 2018 17:45:59 +0800 Subject: [PATCH 1/7] =?UTF-8?q?[FIX]=20=E6=A0=B8=E9=94=80=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E5=BA=94=E6=94=B6=E5=86=B2=E5=BA=94=E4=BB=98=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=94=9F=E6=88=90=E7=BB=93=E7=AE=97=E5=8D=95=20#1866?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- money/models/money_order.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/money/models/money_order.py b/money/models/money_order.py index 98e2cef59..5c31aee0c 100644 --- a/money/models/money_order.py +++ b/money/models/money_order.py @@ -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 @@ -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': From 88209601e52f02b4989d43182b4bb786dcf1dc39 Mon Sep 17 00:00:00 2001 From: flora Date: Wed, 11 Jul 2018 19:15:36 +0800 Subject: [PATCH 2/7] =?UTF-8?q?[ADD]=E5=A2=9E=E5=8A=A0sell=5Fto=5Fbuy?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=8F=8A=E5=85=B6=E4=BB=96=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buy/tests/test_buy_order.py | 6 ++++ sell/tests/test_sell_adjust.py | 12 ++++++++ sell/tests/test_sell_order.py | 6 ++++ sell_to_buy/models/buy.py | 2 ++ sell_to_buy/models/sell.py | 2 +- sell_to_buy/tests/__init__.py | 3 ++ sell_to_buy/tests/test_buy.py | 24 +++++++++++++++ sell_to_buy/tests/test_wizard.py | 37 ++++++++++++++++++++++++ sell_to_buy/wizard/sell_to_buy_wizard.py | 2 ++ 9 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 sell_to_buy/tests/__init__.py create mode 100644 sell_to_buy/tests/test_buy.py create mode 100644 sell_to_buy/tests/test_wizard.py diff --git a/buy/tests/test_buy_order.py b/buy/tests/test_buy_order.py index 58e757147..5fc030710 100644 --- a/buy/tests/test_buy_order.py +++ b/buy/tests/test_buy_order.py @@ -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): diff --git a/sell/tests/test_sell_adjust.py b/sell/tests/test_sell_adjust.py index bdb74338d..63bc4e74f 100644 --- a/sell/tests/test_sell_adjust.py +++ b/sell/tests/test_sell_adjust.py @@ -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): diff --git a/sell/tests/test_sell_order.py b/sell/tests/test_sell_order.py index d4f63bd3d..1408b9325 100644 --- a/sell/tests/test_sell_order.py +++ b/sell/tests/test_sell_order.py @@ -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): diff --git a/sell_to_buy/models/buy.py b/sell_to_buy/models/buy.py index e37c94d36..50f30ae25 100644 --- a/sell_to_buy/models/buy.py +++ b/sell_to_buy/models/buy.py @@ -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'关联的销货订单') @@ -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'对应的销货订单行') diff --git a/sell_to_buy/models/sell.py b/sell_to_buy/models/sell.py index 11bace0db..054fd828a 100644 --- a/sell_to_buy/models/sell.py +++ b/sell_to_buy/models/sell.py @@ -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) diff --git a/sell_to_buy/tests/__init__.py b/sell_to_buy/tests/__init__.py new file mode 100644 index 000000000..0b7238b67 --- /dev/null +++ b/sell_to_buy/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +import test_buy +import test_wizard diff --git a/sell_to_buy/tests/test_buy.py b/sell_to_buy/tests/test_buy.py new file mode 100644 index 000000000..51dd3ee85 --- /dev/null +++ b/sell_to_buy/tests/test_buy.py @@ -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() diff --git a/sell_to_buy/tests/test_wizard.py b/sell_to_buy/tests/test_wizard.py new file mode 100644 index 000000000..c920b630a --- /dev/null +++ b/sell_to_buy/tests/test_wizard.py @@ -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() diff --git a/sell_to_buy/wizard/sell_to_buy_wizard.py b/sell_to_buy/wizard/sell_to_buy_wizard.py index d4fd06ca0..fbbeb1b6e 100644 --- a/sell_to_buy/wizard/sell_to_buy_wizard.py +++ b/sell_to_buy/wizard/sell_to_buy_wizard.py @@ -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 = {} # 用来判断勾选行是否来自同一张销货订单 From e788ff529011941c415afe3c8bb934048ec21bd8 Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 12 Jul 2018 09:48:21 +0800 Subject: [PATCH 3/7] =?UTF-8?q?[REM]=E4=B8=8D=E6=8C=89=E6=94=B6=E8=B4=A7?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E6=97=B6=E5=85=A5=E5=BA=93=E5=8D=95=E4=B8=8A?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E7=8A=B6=E6=80=81=E6=B2=A1=E6=9C=89=E5=8F=82?= =?UTF-8?q?=E8=80=83=E6=84=8F=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buy/models/buy_receipt.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/buy/models/buy_receipt.py b/buy/models/buy_receipt.py index 2e940f9bd..43f7adc54 100644 --- a/buy/models/buy_receipt.py +++ b/buy/models/buy_receipt.py @@ -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: @@ -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: From 57d25ad4aaf617c393ef12619fdef994c95302b6 Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 12 Jul 2018 10:02:55 +0800 Subject: [PATCH 4/7] =?UTF-8?q?[IMP]=E5=B7=B2=E9=87=87=E8=B4=AD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=87=BA=E6=9D=A5=EF=BC=8C=E6=8C=89=E9=92=AE=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sell_to_buy/models/sell.py | 2 +- sell_to_buy/views/buy_view.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sell_to_buy/models/sell.py b/sell_to_buy/models/sell.py index 054fd828a..ad9e7e12d 100644 --- a/sell_to_buy/models/sell.py +++ b/sell_to_buy/models/sell.py @@ -6,4 +6,4 @@ class sell_order_line(models.Model): _inherit = "sell.order.line" - is_bought = fields.Boolean(u'已采购', copy=False) + is_bought = fields.Boolean(u'已采购', copy=False, readonly=True) diff --git a/sell_to_buy/views/buy_view.xml b/sell_to_buy/views/buy_view.xml index 45daeddd9..dee6ab696 100644 --- a/sell_to_buy/views/buy_view.xml +++ b/sell_to_buy/views/buy_view.xml @@ -6,7 +6,7 @@ @@ -23,7 +23,7 @@ - + From 484d9a2c146038a834bda14fc497ef6d56ad8147 Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 12 Jul 2018 10:08:57 +0800 Subject: [PATCH 5/7] =?UTF-8?q?[IMP]goods=5Fcode=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BD=91=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goods_code/__init__.py | 2 -- goods_code/__manifest__.py | 2 +- goods_code/models/__init__.py | 2 -- goods_code/models/goods.py | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/goods_code/__init__.py b/goods_code/__init__.py index 46e3ff224..cde864bae 100644 --- a/goods_code/__init__.py +++ b/goods_code/__init__.py @@ -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 diff --git a/goods_code/__manifest__.py b/goods_code/__manifest__.py index 93117eae3..179bfd92d 100644 --- a/goods_code/__manifest__.py +++ b/goods_code/__manifest__.py @@ -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). { diff --git a/goods_code/models/__init__.py b/goods_code/models/__init__.py index 816bf5aee..4897ffd31 100644 --- a/goods_code/models/__init__.py +++ b/goods_code/models/__init__.py @@ -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 diff --git a/goods_code/models/goods.py b/goods_code/models/goods.py index cc25f23dc..d6e0cd8b1 100644 --- a/goods_code/models/goods.py +++ b/goods_code/models/goods.py @@ -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 From bcf4fa004c98ee0b5d989d621a986502d32a513c Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 12 Jul 2018 11:31:52 +0800 Subject: [PATCH 6/7] =?UTF-8?q?[ADD]sell=5Fdelivery=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sell/models/sell_delivery.py | 8 +++----- sell/tests/test_sell_delivery.py | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sell/models/sell_delivery.py b/sell/models/sell_delivery.py index f649db6ef..dcf789ebe 100644 --- a/sell/models/sell_delivery.py +++ b/sell/models/sell_delivery.py @@ -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) diff --git a/sell/tests/test_sell_delivery.py b/sell/tests/test_sell_delivery.py index e064f9422..08b9ab8af 100644 --- a/sell/tests/test_sell_delivery.py +++ b/sell/tests/test_sell_delivery.py @@ -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): From 00d97ccb657cfbe9afea9f093c0a332333ae50b6 Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 12 Jul 2018 11:33:34 +0800 Subject: [PATCH 7/7] =?UTF-8?q?[FIX]=E4=BF=AE=E6=94=B9=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E4=BC=99=E4=BC=B4=E6=9C=9F=E5=88=9D=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA0=E6=97=B6=E4=B9=9F=E9=9C=80=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BB=A5=E5=89=8D=E7=9A=84=E7=BB=93=E7=AE=97=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- money/models/partner.py | 50 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/money/models/partner.py b/money/models/partner.py index a18322f44..b396d52cd 100644 --- a/money/models/partner.py +++ b/money/models/partner.py @@ -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, @@ -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, @@ -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, @@ -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'期初',