mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] account_payment_purchase: black, isort
This commit is contained in:
@@ -3,22 +3,15 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': 'Account Payment Purchase',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Banking addons',
|
||||
'license': 'AGPL-3',
|
||||
'summary': "Adds Bank Account and Payment Mode on Purchase Orders",
|
||||
'author': "Akretion, "
|
||||
"Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
'website': 'https://github.com/OCA/bank-payment',
|
||||
'depends': [
|
||||
'account_payment_partner',
|
||||
'purchase_stock',
|
||||
],
|
||||
'data': [
|
||||
'views/purchase_order_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
"name": "Account Payment Purchase",
|
||||
"version": "12.0.1.0.0",
|
||||
"category": "Banking addons",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Adds Bank Account and Payment Mode on Purchase Orders",
|
||||
"author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"depends": ["account_payment_partner", "purchase_stock"],
|
||||
"data": ["views/purchase_order_view.xml"],
|
||||
"installable": True,
|
||||
"auto_install": True,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import account_invoice
|
||||
from . import purchase_order
|
||||
from . import stock_rule
|
||||
from . import account_invoice, purchase_order, stock_rule
|
||||
|
||||
@@ -8,24 +8,24 @@ from odoo import _, api, models
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
@api.onchange('purchase_id')
|
||||
@api.onchange("purchase_id")
|
||||
def purchase_order_change(self):
|
||||
new_mode = self.purchase_id.payment_mode_id.id or False
|
||||
new_bank = self.purchase_id.supplier_partner_bank_id.id or False
|
||||
res = super(AccountInvoice, self).purchase_order_change()
|
||||
if self.payment_mode_id and self.payment_mode_id.id != new_mode:
|
||||
res['warning'] = {
|
||||
'title': _('Warning'),
|
||||
'message': _('Selected purchase order have different '
|
||||
'payment mode.'),
|
||||
res["warning"] = {
|
||||
"title": _("Warning"),
|
||||
"message": _("Selected purchase order have different " "payment mode."),
|
||||
}
|
||||
return res
|
||||
self.payment_mode_id = new_mode
|
||||
if self.partner_bank_id and self.partner_bank_id.id != new_bank:
|
||||
res['warning'] = {
|
||||
'title': _('Warning'),
|
||||
'message': _('Selected purchase order have different '
|
||||
'supplier bank.'),
|
||||
res["warning"] = {
|
||||
"title": _("Warning"),
|
||||
"message": _(
|
||||
"Selected purchase order have different " "supplier bank."
|
||||
),
|
||||
}
|
||||
return res
|
||||
self.partner_bank_id = new_bank
|
||||
|
||||
@@ -9,16 +9,16 @@ class PurchaseOrder(models.Model):
|
||||
_inherit = "purchase.order"
|
||||
|
||||
supplier_partner_bank_id = fields.Many2one(
|
||||
comodel_name='res.partner.bank',
|
||||
string='Supplier Bank Account',
|
||||
comodel_name="res.partner.bank",
|
||||
string="Supplier Bank Account",
|
||||
domain="[('partner_id', '=', partner_id)]",
|
||||
help="Select the bank account of your supplier on which your company "
|
||||
"should send the payment. This field is copied from the partner "
|
||||
"and will be copied to the supplier invoice.",
|
||||
"should send the payment. This field is copied from the partner "
|
||||
"and will be copied to the supplier invoice.",
|
||||
)
|
||||
payment_mode_id = fields.Many2one(
|
||||
comodel_name='account.payment.mode',
|
||||
string='Payment Mode',
|
||||
comodel_name="account.payment.mode",
|
||||
string="Payment Mode",
|
||||
domain="[('payment_type', '=', 'outbound')]",
|
||||
)
|
||||
|
||||
@@ -27,12 +27,13 @@ class PurchaseOrder(models.Model):
|
||||
"""This function is designed to be inherited"""
|
||||
return partner.bank_ids and partner.bank_ids[0].id or False
|
||||
|
||||
@api.onchange('partner_id')
|
||||
@api.onchange("partner_id")
|
||||
def onchange_partner_id(self):
|
||||
super(PurchaseOrder, self).onchange_partner_id()
|
||||
if self.partner_id:
|
||||
self.supplier_partner_bank_id = \
|
||||
self._get_default_supplier_partner_bank(self.partner_id)
|
||||
self.supplier_partner_bank_id = self._get_default_supplier_partner_bank(
|
||||
self.partner_id
|
||||
)
|
||||
self.payment_mode_id = self.partner_id.supplier_payment_mode_id
|
||||
else:
|
||||
self.supplier_partner_bank_id = False
|
||||
|
||||
@@ -7,15 +7,18 @@ from odoo import models
|
||||
class StockRule(models.Model):
|
||||
_inherit = "stock.rule"
|
||||
|
||||
def _prepare_purchase_order(self, product_id, product_qty, product_uom,
|
||||
origin, values, partner):
|
||||
def _prepare_purchase_order(
|
||||
self, product_id, product_qty, product_uom, origin, values, partner
|
||||
):
|
||||
"""Propagate payment mode on MTO/drop shipping."""
|
||||
values = super(StockRule, self)._prepare_purchase_order(
|
||||
product_id, product_qty, product_uom, origin, values, partner)
|
||||
product_id, product_qty, product_uom, origin, values, partner
|
||||
)
|
||||
if partner:
|
||||
values['payment_mode_id'] = partner.with_context(
|
||||
force_company=self.company_id.id).supplier_payment_mode_id.id
|
||||
values['supplier_partner_bank_id'] = (
|
||||
self.env['purchase.order']._get_default_supplier_partner_bank(
|
||||
partner))
|
||||
values["payment_mode_id"] = partner.with_context(
|
||||
force_company=self.company_id.id
|
||||
).supplier_payment_mode_id.id
|
||||
values["supplier_partner_bank_id"] = self.env[
|
||||
"purchase.order"
|
||||
]._get_default_supplier_partner_bank(partner)
|
||||
return values
|
||||
|
||||
@@ -10,45 +10,66 @@ class TestAccountPaymentPurchase(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAccountPaymentPurchase, cls).setUpClass()
|
||||
cls.journal = cls.env['account.journal'].create(
|
||||
{'name': 'Test journal',
|
||||
'code': 'TEST',
|
||||
'type': 'general'})
|
||||
cls.payment_mode = cls.env['account.payment.mode'].create(
|
||||
{'name': 'Test payment mode',
|
||||
'fixed_journal_id': cls.journal.id,
|
||||
'bank_account_link': 'variable',
|
||||
'payment_method_id': cls.env.ref(
|
||||
'account.account_payment_method_manual_in').id})
|
||||
cls.partner = cls.env['res.partner'].create(
|
||||
{'name': 'Test partner',
|
||||
'supplier_payment_mode_id': cls.payment_mode.id})
|
||||
cls.bank = cls.env['res.partner.bank'].create(
|
||||
{'bank_name': 'Test bank',
|
||||
'acc_number': '1234567890',
|
||||
'partner_id': cls.partner.id,
|
||||
})
|
||||
cls.bank2 = cls.env['res.partner.bank'].create(
|
||||
{'bank_name': 'Test bank #2',
|
||||
'acc_number': '0123456789',
|
||||
'partner_id': cls.partner.id,
|
||||
})
|
||||
cls.uom_id = cls.env.ref('uom.product_uom_unit').id
|
||||
cls.mto_product = cls.env['product.product'].create(
|
||||
{'name': 'Test buy product',
|
||||
'type': 'product',
|
||||
'uom_id': cls.uom_id,
|
||||
'uom_po_id': cls.uom_id,
|
||||
'seller_ids': [(0, 0, {'name': cls.partner.id})]})
|
||||
cls.purchase = cls.env['purchase.order'].create(
|
||||
{'partner_id': cls.partner.id,
|
||||
'payment_mode_id': cls.payment_mode.id,
|
||||
'order_line': [(0, 0, {'name': 'Test line',
|
||||
'product_qty': 1.0,
|
||||
'product_id': cls.mto_product.id,
|
||||
'product_uom': cls.uom_id,
|
||||
'date_planned': fields.Date.today(),
|
||||
'price_unit': 1.0})]})
|
||||
cls.journal = cls.env["account.journal"].create(
|
||||
{"name": "Test journal", "code": "TEST", "type": "general"}
|
||||
)
|
||||
cls.payment_mode = cls.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Test payment mode",
|
||||
"fixed_journal_id": cls.journal.id,
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_in"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
cls.partner = cls.env["res.partner"].create(
|
||||
{"name": "Test partner", "supplier_payment_mode_id": cls.payment_mode.id}
|
||||
)
|
||||
cls.bank = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"bank_name": "Test bank",
|
||||
"acc_number": "1234567890",
|
||||
"partner_id": cls.partner.id,
|
||||
}
|
||||
)
|
||||
cls.bank2 = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"bank_name": "Test bank #2",
|
||||
"acc_number": "0123456789",
|
||||
"partner_id": cls.partner.id,
|
||||
}
|
||||
)
|
||||
cls.uom_id = cls.env.ref("uom.product_uom_unit").id
|
||||
cls.mto_product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test buy product",
|
||||
"type": "product",
|
||||
"uom_id": cls.uom_id,
|
||||
"uom_po_id": cls.uom_id,
|
||||
"seller_ids": [(0, 0, {"name": cls.partner.id})],
|
||||
}
|
||||
)
|
||||
cls.purchase = cls.env["purchase.order"].create(
|
||||
{
|
||||
"partner_id": cls.partner.id,
|
||||
"payment_mode_id": cls.payment_mode.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Test line",
|
||||
"product_qty": 1.0,
|
||||
"product_id": cls.mto_product.id,
|
||||
"product_uom": cls.uom_id,
|
||||
"date_planned": fields.Date.today(),
|
||||
"price_unit": 1.0,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def test_onchange_partner_id_purchase_order(self):
|
||||
self.purchase.onchange_partner_id()
|
||||
@@ -58,35 +79,40 @@ class TestAccountPaymentPurchase(common.SavepointCase):
|
||||
self.purchase.button_confirm()
|
||||
picking = self.purchase.picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.move_lines.write({'quantity_done': 1.0})
|
||||
picking.move_lines.write({"quantity_done": 1.0})
|
||||
picking.button_validate()
|
||||
|
||||
invoice = self.env['account.invoice'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'purchase_id': self.purchase.id,
|
||||
'account_id': self.partner.property_account_payable_id.id,
|
||||
})
|
||||
invoice = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"purchase_id": self.purchase.id,
|
||||
"account_id": self.partner.property_account_payable_id.id,
|
||||
}
|
||||
)
|
||||
invoice.purchase_order_change()
|
||||
self.assertEqual(
|
||||
self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode)
|
||||
self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode
|
||||
)
|
||||
|
||||
def test_picking_from_purchase_order_invoicing(self):
|
||||
# Test payment mode
|
||||
stockable_product = self.env['product.product'].create(
|
||||
{'name': 'Test stockable product',
|
||||
'type': 'product'})
|
||||
stockable_product = self.env["product.product"].create(
|
||||
{"name": "Test stockable product", "type": "product"}
|
||||
)
|
||||
self.purchase.order_line[0].product_id = stockable_product.id
|
||||
self.purchase.button_confirm()
|
||||
picking = self.purchase.picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.move_lines.write({'quantity_done': 1.0})
|
||||
picking.move_lines.write({"quantity_done": 1.0})
|
||||
picking.button_validate()
|
||||
|
||||
invoice = self.env['account.invoice'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'purchase_id': self.purchase.id,
|
||||
'account_id': self.partner.property_account_payable_id.id,
|
||||
})
|
||||
invoice = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"purchase_id": self.purchase.id,
|
||||
"account_id": self.partner.property_account_payable_id.id,
|
||||
}
|
||||
)
|
||||
invoice.purchase_order_change()
|
||||
self.assertEqual(invoice.payment_mode_id, self.payment_mode)
|
||||
purchase2 = self.purchase.copy()
|
||||
@@ -95,31 +121,33 @@ class TestAccountPaymentPurchase(common.SavepointCase):
|
||||
purchase2.button_confirm()
|
||||
picking = purchase2.picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.move_lines.write({'quantity_done': 1.0})
|
||||
picking.move_lines.write({"quantity_done": 1.0})
|
||||
picking.button_validate()
|
||||
invoice.purchase_id = purchase2.id
|
||||
result = invoice.purchase_order_change()
|
||||
self.assertEqual(result['warning']['title'], 'Warning')
|
||||
self.assertEqual(result["warning"]["title"], "Warning")
|
||||
|
||||
def test_picking_from_purchase_order_invoicing_bank(self):
|
||||
# Test patner_bank
|
||||
stockable_product = self.env['product.product'].create(
|
||||
{'name': 'Test stockable product',
|
||||
'type': 'product'})
|
||||
stockable_product = self.env["product.product"].create(
|
||||
{"name": "Test stockable product", "type": "product"}
|
||||
)
|
||||
self.purchase.order_line[0].product_id = stockable_product.id
|
||||
self.purchase.payment_mode_id = False
|
||||
self.purchase.supplier_partner_bank_id = self.bank.id
|
||||
self.purchase.button_confirm()
|
||||
picking = self.purchase.picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.move_lines.write({'quantity_done': 1.0})
|
||||
picking.move_lines.write({"quantity_done": 1.0})
|
||||
picking.button_validate()
|
||||
|
||||
invoice = self.env['account.invoice'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'purchase_id': self.purchase.id,
|
||||
'account_id': self.partner.property_account_payable_id.id,
|
||||
})
|
||||
invoice = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"purchase_id": self.purchase.id,
|
||||
"account_id": self.partner.property_account_payable_id.id,
|
||||
}
|
||||
)
|
||||
# Avoid bank company from default_get method
|
||||
invoice.partner_bank_id = False
|
||||
invoice.purchase_order_change()
|
||||
@@ -129,27 +157,26 @@ class TestAccountPaymentPurchase(common.SavepointCase):
|
||||
purchase2.button_confirm()
|
||||
picking = purchase2.picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.move_lines.write({'quantity_done': 1.0})
|
||||
picking.move_lines.write({"quantity_done": 1.0})
|
||||
picking.button_validate()
|
||||
invoice.purchase_id = purchase2.id
|
||||
result = invoice.purchase_order_change()
|
||||
self.assertEqual(result['warning']['title'], 'Warning')
|
||||
self.assertEqual(result["warning"]["title"], "Warning")
|
||||
|
||||
def test_procurement_buy_payment_mode(self):
|
||||
route = self.env.ref('purchase_stock.route_warehouse0_buy')
|
||||
rule = self.env['stock.rule'].search(
|
||||
[('route_id', '=', route.id)], limit=1)
|
||||
route = self.env.ref("purchase_stock.route_warehouse0_buy")
|
||||
rule = self.env["stock.rule"].search([("route_id", "=", route.id)], limit=1)
|
||||
rule._run_buy(
|
||||
product_id=self.mto_product,
|
||||
product_qty=1,
|
||||
product_uom=self.mto_product.uom_id,
|
||||
location_id=self.env['stock.location'].search([], limit=1),
|
||||
name='Procurement order test',
|
||||
origin='Test',
|
||||
location_id=self.env["stock.location"].search([], limit=1),
|
||||
name="Procurement order test",
|
||||
origin="Test",
|
||||
values={
|
||||
'company_id': self.env.user.company_id,
|
||||
'date_planned': fields.Datetime.now(),
|
||||
"company_id": self.env.user.company_id,
|
||||
"date_planned": fields.Datetime.now(),
|
||||
},
|
||||
)
|
||||
purchase = self.env['purchase.order'].search([('origin', '=', 'Test')])
|
||||
purchase = self.env["purchase.order"].search([("origin", "=", "Test")])
|
||||
self.assertEqual(purchase.payment_mode_id, self.payment_mode)
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2014 - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
Copyright 2017 - Tecnativa <vicent.cubells@tecnativa.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
|
||||
<record id="purchase_order_form" model="ir.ui.view">
|
||||
<field name="name">account_payment_purchase.purchase_order.form</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_term_id" position="after">
|
||||
<field name="payment_mode_id"
|
||||
<field
|
||||
name="payment_mode_id"
|
||||
domain="[('payment_type', '=', 'outbound')]"
|
||||
widget="selection"/>
|
||||
<field name="supplier_partner_bank_id"/>
|
||||
widget="selection"
|
||||
/>
|
||||
<field name="supplier_partner_bank_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user