[IMP] account_move_line_purchase_info: black, isort
This commit is contained in:
parent
e2ea358229
commit
438d620eb6
@ -6,15 +6,11 @@
|
|||||||
"name": "Account Move Line Purchase Info",
|
"name": "Account Move Line Purchase Info",
|
||||||
"summary": "Introduces the purchase order line to the journal items",
|
"summary": "Introduces the purchase order line to the journal items",
|
||||||
"version": "12.0.2.0.0",
|
"version": "12.0.2.0.0",
|
||||||
"author": "Eficent, "
|
"author": "Eficent, " "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
|
||||||
"website": "https://www.github.com/OCA/account-financial-tools",
|
"website": "https://www.github.com/OCA/account-financial-tools",
|
||||||
"category": "Generic",
|
"category": "Generic",
|
||||||
"depends": ["purchase_stock"],
|
"depends": ["purchase_stock"],
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"data": [
|
"data": ["security/account_security.xml", "views/account_move_view.xml"],
|
||||||
"security/account_security.xml",
|
"installable": True,
|
||||||
"views/account_move_view.xml",
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
}
|
}
|
||||||
|
@ -4,23 +4,25 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
__name__ = "Upgrade to 12.0.2.0.0"
|
__name__ = "Upgrade to 12.0.2.0.0"
|
||||||
|
|
||||||
|
|
||||||
def update_purchase_id_column(cr):
|
def update_purchase_id_column(cr):
|
||||||
cr.execute("""SELECT column_name
|
cr.execute(
|
||||||
|
"""SELECT column_name
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
WHERE table_name='account_move_line' AND
|
WHERE table_name='account_move_line' AND
|
||||||
column_name='purchase_id'""")
|
column_name='purchase_id'"""
|
||||||
|
)
|
||||||
if not cr.fetchone():
|
if not cr.fetchone():
|
||||||
_logger.info("""Add column purchase_id to account_move_line""")
|
_logger.info("""Add column purchase_id to account_move_line""")
|
||||||
cr.execute(
|
cr.execute(
|
||||||
"""
|
"""
|
||||||
ALTER TABLE account_move_line ADD COLUMN purchase_id integer;
|
ALTER TABLE account_move_line ADD COLUMN purchase_id integer;
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
_logger.info("""Updating values for purchase_id in account_move_line""")
|
_logger.info("""Updating values for purchase_id in account_move_line""")
|
||||||
cr.execute(
|
cr.execute(
|
||||||
"""
|
"""
|
||||||
|
@ -2,4 +2,3 @@ from . import account_move
|
|||||||
from . import account_invoice
|
from . import account_invoice
|
||||||
from . import purchase_order_line
|
from . import purchase_order_line
|
||||||
from . import stock_move
|
from . import stock_move
|
||||||
|
|
||||||
|
@ -7,23 +7,23 @@ from odoo import api, models
|
|||||||
|
|
||||||
class AccountInvoice(models.Model):
|
class AccountInvoice(models.Model):
|
||||||
|
|
||||||
_inherit = 'account.invoice'
|
_inherit = "account.invoice"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def invoice_line_move_line_get(self):
|
def invoice_line_move_line_get(self):
|
||||||
res = super(AccountInvoice, self).invoice_line_move_line_get()
|
res = super(AccountInvoice, self).invoice_line_move_line_get()
|
||||||
|
|
||||||
invoice_line_model = self.env['account.invoice.line']
|
invoice_line_model = self.env["account.invoice.line"]
|
||||||
for move_line_dict in res:
|
for move_line_dict in res:
|
||||||
if 'invl_id' in move_line_dict:
|
if "invl_id" in move_line_dict:
|
||||||
line = invoice_line_model.browse(move_line_dict['invl_id'])
|
line = invoice_line_model.browse(move_line_dict["invl_id"])
|
||||||
move_line_dict['purchase_line_id'] = line.purchase_line_id.id
|
move_line_dict["purchase_line_id"] = line.purchase_line_id.id
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def line_get_convert(self, line, part):
|
def line_get_convert(self, line, part):
|
||||||
res = super(AccountInvoice, self).line_get_convert(line, part)
|
res = super(AccountInvoice, self).line_get_convert(line, part)
|
||||||
if line.get('purchase_line_id', False):
|
if line.get("purchase_line_id", False):
|
||||||
res['purchase_line_id'] = line.get('purchase_line_id')
|
res["purchase_line_id"] = line.get("purchase_line_id")
|
||||||
return res
|
return res
|
||||||
|
@ -7,17 +7,19 @@ from odoo import fields, models
|
|||||||
|
|
||||||
class AccountMoveLine(models.Model):
|
class AccountMoveLine(models.Model):
|
||||||
|
|
||||||
_inherit = 'account.move.line'
|
_inherit = "account.move.line"
|
||||||
|
|
||||||
purchase_line_id = fields.Many2one(
|
purchase_line_id = fields.Many2one(
|
||||||
comodel_name='purchase.order.line',
|
comodel_name="purchase.order.line",
|
||||||
string='Purchase Order Line',
|
string="Purchase Order Line",
|
||||||
ondelete='set null', index=True,
|
ondelete="set null",
|
||||||
|
index=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
purchase_id = fields.Many2one(
|
purchase_id = fields.Many2one(
|
||||||
comodel_name='purchase.order',
|
comodel_name="purchase.order",
|
||||||
related='purchase_line_id.order_id',
|
related="purchase_line_id.order_id",
|
||||||
string='Purchase Order',
|
string="Purchase Order",
|
||||||
store=True, index=True,
|
store=True,
|
||||||
|
index=True,
|
||||||
)
|
)
|
||||||
|
@ -13,8 +13,7 @@ class PurchaseOrderLine(models.Model):
|
|||||||
orig_name = dict(super(PurchaseOrderLine, self).name_get())
|
orig_name = dict(super(PurchaseOrderLine, self).name_get())
|
||||||
for line in self:
|
for line in self:
|
||||||
name = orig_name[line.id]
|
name = orig_name[line.id]
|
||||||
if self.env.context.get('po_line_info', False):
|
if self.env.context.get("po_line_info", False):
|
||||||
name = "[%s] %s (%s)" % (line.order_id.name, name,
|
name = "[{}] {} ({})".format(line.order_id.name, name, line.order_id.state)
|
||||||
line.order_id.state)
|
|
||||||
result.append((line.id, name))
|
result.append((line.id, name))
|
||||||
return result
|
return result
|
||||||
|
@ -9,10 +9,12 @@ class StockMove(models.Model):
|
|||||||
_inherit = "stock.move"
|
_inherit = "stock.move"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_account_move_line(self, qty, cost,
|
def _prepare_account_move_line(
|
||||||
credit_account_id, debit_account_id):
|
self, qty, cost, credit_account_id, debit_account_id
|
||||||
|
):
|
||||||
res = super(StockMove, self)._prepare_account_move_line(
|
res = super(StockMove, self)._prepare_account_move_line(
|
||||||
qty, cost, credit_account_id, debit_account_id)
|
qty, cost, credit_account_id, debit_account_id
|
||||||
|
)
|
||||||
for line in res:
|
for line in res:
|
||||||
line[2]['purchase_line_id'] = self.purchase_line_id.id
|
line[2]["purchase_line_id"] = self.purchase_line_id.id
|
||||||
return res
|
return res
|
||||||
|
@ -2,118 +2,118 @@
|
|||||||
# (www.eficent.com)
|
# (www.eficent.com)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.tests import common
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
|
class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAccountMoveLinePurchaseInfo, self).setUp()
|
super(TestAccountMoveLinePurchaseInfo, self).setUp()
|
||||||
self.purchase_model = self.env['purchase.order']
|
self.purchase_model = self.env["purchase.order"]
|
||||||
self.purchase_line_model = self.env['purchase.order.line']
|
self.purchase_line_model = self.env["purchase.order.line"]
|
||||||
self.invoice_model = self.env['account.invoice']
|
self.invoice_model = self.env["account.invoice"]
|
||||||
self.invoice_line_model = self.env['account.invoice.line']
|
self.invoice_line_model = self.env["account.invoice.line"]
|
||||||
self.product_model = self.env['product.product']
|
self.product_model = self.env["product.product"]
|
||||||
self.product_ctg_model = self.env['product.category']
|
self.product_ctg_model = self.env["product.category"]
|
||||||
self.acc_type_model = self.env['account.account.type']
|
self.acc_type_model = self.env["account.account.type"]
|
||||||
self.account_model = self.env['account.account']
|
self.account_model = self.env["account.account"]
|
||||||
self.aml_model = self.env['account.move.line']
|
self.aml_model = self.env["account.move.line"]
|
||||||
self.res_users_model = self.env['res.users']
|
self.res_users_model = self.env["res.users"]
|
||||||
|
|
||||||
self.partner1 = self.env.ref('base.res_partner_1')
|
self.partner1 = self.env.ref("base.res_partner_1")
|
||||||
self.location_stock = self.env.ref('stock.stock_location_stock')
|
self.location_stock = self.env.ref("stock.stock_location_stock")
|
||||||
self.company = self.env.ref('base.main_company')
|
self.company = self.env.ref("base.main_company")
|
||||||
self.group_purchase_user = self.env.ref('purchase.group_purchase_user')
|
self.group_purchase_user = self.env.ref("purchase.group_purchase_user")
|
||||||
self.group_account_invoice = self.env.ref(
|
self.group_account_invoice = self.env.ref("account.group_account_invoice")
|
||||||
'account.group_account_invoice')
|
self.group_account_manager = self.env.ref("account.group_account_manager")
|
||||||
self.group_account_manager = self.env.ref(
|
|
||||||
'account.group_account_manager')
|
|
||||||
|
|
||||||
# Create account for Goods Received Not Invoiced
|
# Create account for Goods Received Not Invoiced
|
||||||
acc_type = self._create_account_type('equity', 'other')
|
acc_type = self._create_account_type("equity", "other")
|
||||||
name = 'Goods Received Not Invoiced'
|
name = "Goods Received Not Invoiced"
|
||||||
code = 'grni'
|
code = "grni"
|
||||||
self.account_grni = self._create_account(acc_type, name, code,
|
self.account_grni = self._create_account(acc_type, name, code, self.company)
|
||||||
self.company)
|
|
||||||
|
|
||||||
# Create account for Cost of Goods Sold
|
# Create account for Cost of Goods Sold
|
||||||
acc_type = self._create_account_type('expense', 'other')
|
acc_type = self._create_account_type("expense", "other")
|
||||||
name = 'Cost of Goods Sold'
|
name = "Cost of Goods Sold"
|
||||||
code = 'cogs'
|
code = "cogs"
|
||||||
self.account_cogs = self._create_account(acc_type, name, code,
|
self.account_cogs = self._create_account(acc_type, name, code, self.company)
|
||||||
self.company)
|
|
||||||
# Create account for Inventory
|
# Create account for Inventory
|
||||||
acc_type = self._create_account_type('asset', 'other')
|
acc_type = self._create_account_type("asset", "other")
|
||||||
name = 'Inventory'
|
name = "Inventory"
|
||||||
code = 'inventory'
|
code = "inventory"
|
||||||
self.account_inventory = self._create_account(acc_type, name, code,
|
self.account_inventory = self._create_account(
|
||||||
self.company)
|
acc_type, name, code, self.company
|
||||||
|
)
|
||||||
# Create Product
|
# Create Product
|
||||||
self.product = self._create_product()
|
self.product = self._create_product()
|
||||||
|
|
||||||
# Create users
|
# Create users
|
||||||
self.purchase_user = self._create_user('purchase_user',
|
self.purchase_user = self._create_user(
|
||||||
[self.group_purchase_user,
|
"purchase_user",
|
||||||
self.group_account_invoice],
|
[self.group_purchase_user, self.group_account_invoice],
|
||||||
self.company)
|
self.company,
|
||||||
self.account_invoice = self._create_user('account_invoice',
|
)
|
||||||
[self.group_account_invoice],
|
self.account_invoice = self._create_user(
|
||||||
self.company)
|
"account_invoice", [self.group_account_invoice], self.company
|
||||||
self.account_manager = self._create_user('account_manager',
|
)
|
||||||
[self.group_account_manager],
|
self.account_manager = self._create_user(
|
||||||
self.company)
|
"account_manager", [self.group_account_manager], self.company
|
||||||
|
)
|
||||||
|
|
||||||
def _create_user(self, login, groups, company):
|
def _create_user(self, login, groups, company):
|
||||||
""" Create a user."""
|
""" Create a user."""
|
||||||
group_ids = [group.id for group in groups]
|
group_ids = [group.id for group in groups]
|
||||||
user = \
|
user = self.res_users_model.with_context({"no_reset_password": True}).create(
|
||||||
self.res_users_model.with_context(
|
{
|
||||||
{'no_reset_password': True}).create({
|
"name": "Test User",
|
||||||
'name': 'Test User',
|
"login": login,
|
||||||
'login': login,
|
"password": "demo",
|
||||||
'password': 'demo',
|
"email": "test@yourcompany.com",
|
||||||
'email': 'test@yourcompany.com',
|
"company_id": company.id,
|
||||||
'company_id': company.id,
|
"company_ids": [(4, company.id)],
|
||||||
'company_ids': [(4, company.id)],
|
"groups_id": [(6, 0, group_ids)],
|
||||||
'groups_id': [(6, 0, group_ids)]
|
}
|
||||||
})
|
)
|
||||||
return user.id
|
return user.id
|
||||||
|
|
||||||
def _create_account_type(self, name, type):
|
def _create_account_type(self, name, type):
|
||||||
acc_type = self.acc_type_model.create({
|
acc_type = self.acc_type_model.create({"name": name, "type": type})
|
||||||
'name': name,
|
|
||||||
'type': type
|
|
||||||
})
|
|
||||||
return acc_type
|
return acc_type
|
||||||
|
|
||||||
def _create_account(self, acc_type, name, code, company):
|
def _create_account(self, acc_type, name, code, company):
|
||||||
"""Create an account."""
|
"""Create an account."""
|
||||||
account = self.account_model.create({
|
account = self.account_model.create(
|
||||||
'name': name,
|
{
|
||||||
'code': code,
|
"name": name,
|
||||||
'user_type_id': acc_type.id,
|
"code": code,
|
||||||
'company_id': company.id
|
"user_type_id": acc_type.id,
|
||||||
})
|
"company_id": company.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
return account
|
return account
|
||||||
|
|
||||||
def _create_product(self):
|
def _create_product(self):
|
||||||
"""Create a Product."""
|
"""Create a Product."""
|
||||||
# group_ids = [group.id for group in groups]
|
# group_ids = [group.id for group in groups]
|
||||||
product_ctg = self.product_ctg_model.create({
|
product_ctg = self.product_ctg_model.create(
|
||||||
'name': 'test_product_ctg',
|
{
|
||||||
'property_stock_valuation_account_id': self.account_inventory.id,
|
"name": "test_product_ctg",
|
||||||
'property_valuation': 'real_time',
|
"property_stock_valuation_account_id": self.account_inventory.id,
|
||||||
'property_stock_account_input_categ_id': self.account_grni.id,
|
"property_valuation": "real_time",
|
||||||
'property_stock_account_output_categ_id': self.account_cogs.id,
|
"property_stock_account_input_categ_id": self.account_grni.id,
|
||||||
})
|
"property_stock_account_output_categ_id": self.account_cogs.id,
|
||||||
product = self.product_model.create({
|
}
|
||||||
'name': 'test_product',
|
)
|
||||||
'categ_id': product_ctg.id,
|
product = self.product_model.create(
|
||||||
'type': 'product',
|
{
|
||||||
'standard_price': 1.0,
|
"name": "test_product",
|
||||||
'list_price': 1.0,
|
"categ_id": product_ctg.id,
|
||||||
})
|
"type": "product",
|
||||||
|
"standard_price": 1.0,
|
||||||
|
"list_price": 1.0,
|
||||||
|
}
|
||||||
|
)
|
||||||
return product
|
return product
|
||||||
|
|
||||||
def _create_purchase(self, line_products):
|
def _create_purchase(self, line_products):
|
||||||
@ -124,47 +124,48 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
|
|||||||
lines = []
|
lines = []
|
||||||
for product, qty in line_products:
|
for product, qty in line_products:
|
||||||
line_values = {
|
line_values = {
|
||||||
'name': product.name,
|
"name": product.name,
|
||||||
'product_id': product.id,
|
"product_id": product.id,
|
||||||
'product_qty': qty,
|
"product_qty": qty,
|
||||||
'product_uom': product.uom_id.id,
|
"product_uom": product.uom_id.id,
|
||||||
'price_unit': 500,
|
"price_unit": 500,
|
||||||
'date_planned': fields.datetime.now()
|
"date_planned": fields.datetime.now(),
|
||||||
}
|
}
|
||||||
lines.append(
|
lines.append((0, 0, line_values))
|
||||||
(0, 0, line_values)
|
return self.purchase_model.create(
|
||||||
)
|
{"partner_id": self.partner1.id, "order_line": lines}
|
||||||
return self.purchase_model.create({
|
)
|
||||||
'partner_id': self.partner1.id,
|
|
||||||
'order_line': lines,
|
|
||||||
})
|
|
||||||
|
|
||||||
def _get_balance(self, domain):
|
def _get_balance(self, domain):
|
||||||
"""
|
"""
|
||||||
Call read_group method and return the balance of particular account.
|
Call read_group method and return the balance of particular account.
|
||||||
"""
|
"""
|
||||||
aml_rec = self.aml_model.read_group(domain,
|
aml_rec = self.aml_model.read_group(
|
||||||
['debit', 'credit', 'account_id'],
|
domain, ["debit", "credit", "account_id"], ["account_id"]
|
||||||
['account_id'])
|
)
|
||||||
if aml_rec:
|
if aml_rec:
|
||||||
return aml_rec[0].get('debit', 0) - aml_rec[0].get('credit', 0)
|
return aml_rec[0].get("debit", 0) - aml_rec[0].get("credit", 0)
|
||||||
else:
|
else:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def _check_account_balance(self, account_id, purchase_line=None,
|
def _check_account_balance(
|
||||||
expected_balance=0.0):
|
self, account_id, purchase_line=None, expected_balance=0.0
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Check the balance of the account
|
Check the balance of the account
|
||||||
"""
|
"""
|
||||||
domain = [('account_id', '=', account_id)]
|
domain = [("account_id", "=", account_id)]
|
||||||
if purchase_line:
|
if purchase_line:
|
||||||
domain.extend([('purchase_line_id', '=', purchase_line.id)])
|
domain.extend([("purchase_line_id", "=", purchase_line.id)])
|
||||||
|
|
||||||
balance = self._get_balance(domain)
|
balance = self._get_balance(domain)
|
||||||
if purchase_line:
|
if purchase_line:
|
||||||
self.assertEqual(balance, expected_balance,
|
self.assertEqual(
|
||||||
'Balance is not %s for Purchase Line %s.'
|
balance,
|
||||||
% (str(expected_balance), purchase_line.name))
|
expected_balance,
|
||||||
|
"Balance is not %s for Purchase Line %s."
|
||||||
|
% (str(expected_balance), purchase_line.name),
|
||||||
|
)
|
||||||
|
|
||||||
def test_purchase_invoice(self):
|
def test_purchase_invoice(self):
|
||||||
"""Test that the po line moves from the purchase order to the
|
"""Test that the po line moves from the purchase order to the
|
||||||
@ -178,35 +179,48 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
|
|||||||
purchase.button_confirm()
|
purchase.button_confirm()
|
||||||
picking = purchase.picking_ids[0]
|
picking = purchase.picking_ids[0]
|
||||||
picking.action_confirm()
|
picking.action_confirm()
|
||||||
picking.move_lines.write({'quantity_done': 1.0})
|
picking.move_lines.write({"quantity_done": 1.0})
|
||||||
picking.button_validate()
|
picking.button_validate()
|
||||||
|
|
||||||
expected_balance = 1.0
|
expected_balance = 1.0
|
||||||
self._check_account_balance(self.account_inventory.id,
|
self._check_account_balance(
|
||||||
purchase_line=po_line,
|
self.account_inventory.id,
|
||||||
expected_balance=expected_balance)
|
purchase_line=po_line,
|
||||||
|
expected_balance=expected_balance,
|
||||||
|
)
|
||||||
|
|
||||||
invoice = self.invoice_model.create({
|
invoice = self.invoice_model.create(
|
||||||
'partner_id': self.partner1.id,
|
{
|
||||||
'purchase_id': purchase.id,
|
"partner_id": self.partner1.id,
|
||||||
'account_id': purchase.partner_id.property_account_payable_id.id,
|
"purchase_id": purchase.id,
|
||||||
})
|
"account_id": purchase.partner_id.property_account_payable_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
invoice.purchase_order_change()
|
invoice.purchase_order_change()
|
||||||
invoice.action_invoice_open()
|
invoice.action_invoice_open()
|
||||||
|
|
||||||
for aml in invoice.move_id.line_ids:
|
for aml in invoice.move_id.line_ids:
|
||||||
if aml.product_id == po_line.product_id and aml.invoice_id:
|
if aml.product_id == po_line.product_id and aml.invoice_id:
|
||||||
self.assertEqual(aml.purchase_line_id, po_line,
|
self.assertEqual(
|
||||||
'Purchase Order line has not been copied '
|
aml.purchase_line_id,
|
||||||
'from the invoice to the account move line.')
|
po_line,
|
||||||
|
"Purchase Order line has not been copied "
|
||||||
|
"from the invoice to the account move line.",
|
||||||
|
)
|
||||||
|
|
||||||
def test_name_get(self):
|
def test_name_get(self):
|
||||||
purchase = self._create_purchase([(self.product, 1)])
|
purchase = self._create_purchase([(self.product, 1)])
|
||||||
po_line = purchase.order_line[0]
|
po_line = purchase.order_line[0]
|
||||||
name_get = po_line.with_context({'po_line_info': True}).name_get()
|
name_get = po_line.with_context({"po_line_info": True}).name_get()
|
||||||
self.assertEqual(name_get, [(po_line.id, "[%s] %s (%s)" % (
|
self.assertEqual(
|
||||||
po_line.order_id.name, po_line.name,
|
name_get,
|
||||||
po_line.order_id.state,
|
[
|
||||||
))])
|
(
|
||||||
|
po_line.id,
|
||||||
|
"[%s] %s (%s)"
|
||||||
|
% (po_line.order_id.name, po_line.name, po_line.order_id.state),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
name_get_no_ctx = po_line.name_get()
|
name_get_no_ctx = po_line.name_get()
|
||||||
self.assertEqual(name_get_no_ctx, [(po_line.id, po_line.name)])
|
self.assertEqual(name_get_no_ctx, [(po_line.id, po_line.name)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user