diff --git a/account_move_line_sale_info/__manifest__.py b/account_move_line_sale_info/__manifest__.py
index 85625fb5..98fc7507 100644
--- a/account_move_line_sale_info/__manifest__.py
+++ b/account_move_line_sale_info/__manifest__.py
@@ -5,16 +5,12 @@
"name": "Account Move Line Sale Info",
"summary": "Introduces the purchase order line to the journal items",
"version": "11.0.1.0.0",
- "author": "ForgeFlow S.L., "
- "Odoo Community Association (OCA)",
+ "author": "ForgeFlow S.L., " "Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/account-financial-tools",
"category": "Generic",
"depends": ["account_move_line_stock_info", "sale"],
"license": "AGPL-3",
- "data": [
- "security/account_security.xml",
- "views/account_move_view.xml",
- ],
- 'installable': True,
- 'post_init_hook': 'post_init_hook',
+ "data": ["security/account_security.xml", "views/account_move_view.xml",],
+ "installable": True,
+ "post_init_hook": "post_init_hook",
}
diff --git a/account_move_line_sale_info/hooks.py b/account_move_line_sale_info/hooks.py
index 3d5bbab9..f47a472f 100644
--- a/account_move_line_sale_info/hooks.py
+++ b/account_move_line_sale_info/hooks.py
@@ -1,22 +1,26 @@
# Copyright 2019 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import ast
-from odoo import api, SUPERUSER_ID
+
+from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
""" INIT sale references in acount move line """
# FOR stock moves
- cr.execute("""
+ cr.execute(
+ """
update account_move_line aml set sale_line_id = sm.sale_line_id
FROM account_move_line aml2
INNER JOIN stock_move sm ON
aml2.stock_move_id = sm.id
WHERE aml.id = aml2.id;
- """)
+ """
+ )
# FOR invoices
- cr.execute("""
+ cr.execute(
+ """
update account_move_line aml set sale_line_id = sol.id
FROM account_move_line aml2
INNER JOIN account_invoice ai ON
@@ -29,30 +33,36 @@ def post_init_hook(cr, registry):
rel.order_line_id = sol.id
AND sol.product_id = aml2.product_id
WHERE aml.id = aml2.id;
- """)
+ """
+ )
# NOW we can fill the SO
- cr.execute("""
+ cr.execute(
+ """
UPDATE account_move_line aml
SET sale_id = sol.order_id
FROM sale_order_line AS sol
WHERE aml.sale_line_id = sol.id
RETURNING aml.move_id
- """)
+ """
+ )
# NOW we can fill the lines without invoice_id (Odoo put it very
# complicated)
- cr.execute("""
+ cr.execute(
+ """
UPDATE account_move_line aml
SET sale_id = so.id
FROM sale_order_line so
LEFT JOIN account_move_line aml2
- ON aml2.sale_id = so.id
+ ON aml2.sale_id = so.id
WHERE aml2.move_id = aml.move_id
- """)
+ """
+ )
- cr.execute("""
+ cr.execute(
+ """
update account_move_line aml set sale_line_id = sol.id
FROM account_move_line aml2
INNER JOIN sale_order so ON
@@ -61,4 +71,5 @@ def post_init_hook(cr, registry):
so.id = sol.order_id
AND sol.product_id = aml2.product_id
WHERE aml.id = aml2.id;
- """)
+ """
+ )
diff --git a/account_move_line_sale_info/models/account_invoice.py b/account_move_line_sale_info/models/account_invoice.py
index 41a64d68..73d8a555 100644
--- a/account_move_line_sale_info/models/account_invoice.py
+++ b/account_move_line_sale_info/models/account_invoice.py
@@ -6,25 +6,25 @@ from odoo import api, models
class AccountInvoice(models.Model):
- _inherit = 'account.invoice'
+ _inherit = "account.invoice"
@api.model
def invoice_line_move_line_get(self):
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:
- if 'invl_id' in move_line_dict:
- line = invoice_line_model.browse(move_line_dict['invl_id'])
+ if "invl_id" in move_line_dict:
+ line = invoice_line_model.browse(move_line_dict["invl_id"])
if line.sale_line_ids and len(line.sale_line_ids) == 1:
- move_line_dict['sale_line_id'] = line.sale_line_ids[0].id
+ move_line_dict["sale_line_id"] = line.sale_line_ids[0].id
return res
@api.model
def line_get_convert(self, line, part):
res = super(AccountInvoice, self).line_get_convert(line, part)
- if line.get('sale_line_id', False):
- res['sale_line_id'] = line.get('sale_line_id')
+ if line.get("sale_line_id", False):
+ res["sale_line_id"] = line.get("sale_line_id")
return res
@api.model
@@ -35,5 +35,5 @@ class AccountInvoice(models.Model):
res = super()._anglo_saxon_sale_move_lines(i_line)
for aml in res:
if i_line.sale_line_ids and len(i_line.sale_line_ids) == 1:
- aml['sale_line_id'] = i_line.sale_line_ids[0].id
+ aml["sale_line_id"] = i_line.sale_line_ids[0].id
return res
diff --git a/account_move_line_sale_info/models/account_move.py b/account_move_line_sale_info/models/account_move.py
index 01f08368..d84d53cc 100644
--- a/account_move_line_sale_info/models/account_move.py
+++ b/account_move_line_sale_info/models/account_move.py
@@ -6,18 +6,20 @@ from odoo import fields, models
class AccountMoveLine(models.Model):
- _inherit = 'account.move.line'
+ _inherit = "account.move.line"
sale_line_id = fields.Many2one(
- comodel_name='sale.order.line',
- string='Sale Order Line',
- ondelete='set null', index=True,
+ comodel_name="sale.order.line",
+ string="Sale Order Line",
+ ondelete="set null",
+ index=True,
)
sale_id = fields.Many2one(
- comodel_name='sale.order',
- related='sale_line_id.order_id',
- string='Sales Order',
- ondelete='set null',
- store=True, index=True,
+ comodel_name="sale.order",
+ related="sale_line_id.order_id",
+ string="Sales Order",
+ ondelete="set null",
+ store=True,
+ index=True,
)
diff --git a/account_move_line_sale_info/models/sale_order_line.py b/account_move_line_sale_info/models/sale_order_line.py
index ccb9043c..fc103cc4 100644
--- a/account_move_line_sale_info/models/sale_order_line.py
+++ b/account_move_line_sale_info/models/sale_order_line.py
@@ -13,8 +13,7 @@ class SaleOrderLine(models.Model):
orig_name = dict(super(SaleOrderLine, self).name_get())
for line in self:
name = orig_name[line.id]
- if self.env.context.get('so_line_info', False):
- name = "[%s] %s (%s)" % (line.order_id.name, name,
- line.order_id.state)
+ if self.env.context.get("so_line_info", False):
+ name = "[{}] {} ({})".format(line.order_id.name, name, line.order_id.state)
result.append((line.id, name))
return result
diff --git a/account_move_line_sale_info/models/stock_move.py b/account_move_line_sale_info/models/stock_move.py
index a346a016..07b1bb0b 100644
--- a/account_move_line_sale_info/models/stock_move.py
+++ b/account_move_line_sale_info/models/stock_move.py
@@ -7,10 +7,12 @@ class StockMove(models.Model):
_inherit = "stock.move"
@api.model
- def _prepare_account_move_line(self, qty, cost,
- credit_account_id, debit_account_id):
+ def _prepare_account_move_line(
+ self, qty, cost, credit_account_id, debit_account_id
+ ):
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:
- line[2]['sale_line_id'] = self.sale_line_id.id
+ line[2]["sale_line_id"] = self.sale_line_id.id
return res
diff --git a/account_move_line_sale_info/security/account_security.xml b/account_move_line_sale_info/security/account_security.xml
index a6d3ed04..bd3f7e6d 100644
--- a/account_move_line_sale_info/security/account_security.xml
+++ b/account_move_line_sale_info/security/account_security.xml
@@ -1,10 +1,8 @@
-
+
-
Sale info in Journal Items
-
-
+
+
-
diff --git a/account_move_line_sale_info/tests/test_account_move_line_sale_info.py b/account_move_line_sale_info/tests/test_account_move_line_sale_info.py
index a3eaa974..29f62d44 100644
--- a/account_move_line_sale_info/tests/test_account_move_line_sale_info.py
+++ b/account_move_line_sale_info/tests/test_account_move_line_sale_info.py
@@ -1,117 +1,117 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
-from odoo.tests import common
from odoo import fields
+from odoo.tests import common
class TestAccountMoveLineSaleInfo(common.TransactionCase):
-
def setUp(self):
super(TestAccountMoveLineSaleInfo, self).setUp()
- self.sale_model = self.env['sale.order']
- self.sale_line_model = self.env['sale.order.line']
- self.invoice_model = self.env['account.invoice']
- self.invoice_line_model = self.env['account.invoice.line']
- self.product_model = self.env['product.product']
- self.product_ctg_model = self.env['product.category']
- self.acc_type_model = self.env['account.account.type']
- self.account_model = self.env['account.account']
- self.aml_model = self.env['account.move.line']
- self.res_users_model = self.env['res.users']
+ self.sale_model = self.env["sale.order"]
+ self.sale_line_model = self.env["sale.order.line"]
+ self.invoice_model = self.env["account.invoice"]
+ self.invoice_line_model = self.env["account.invoice.line"]
+ self.product_model = self.env["product.product"]
+ self.product_ctg_model = self.env["product.category"]
+ self.acc_type_model = self.env["account.account.type"]
+ self.account_model = self.env["account.account"]
+ self.aml_model = self.env["account.move.line"]
+ self.res_users_model = self.env["res.users"]
- self.partner1 = self.env.ref('base.res_partner_1')
- self.location_stock = self.env.ref('stock.stock_location_stock')
- self.company = self.env.ref('base.main_company')
- self.group_sale_user = self.env.ref('sales_team.group_sale_salesman')
- self.group_account_invoice = self.env.ref(
- 'account.group_account_invoice')
- self.group_account_manager = self.env.ref(
- 'account.group_account_manager')
+ self.partner1 = self.env.ref("base.res_partner_1")
+ self.location_stock = self.env.ref("stock.stock_location_stock")
+ self.company = self.env.ref("base.main_company")
+ self.group_sale_user = self.env.ref("sales_team.group_sale_salesman")
+ self.group_account_invoice = self.env.ref("account.group_account_invoice")
+ self.group_account_manager = self.env.ref("account.group_account_manager")
# Create account for Goods Received Not Invoiced
- acc_type = self._create_account_type('equity', 'other')
- name = 'Goods Received Not Invoiced'
- code = 'grni'
- self.account_grni = self._create_account(acc_type, name, code,
- self.company)
+ acc_type = self._create_account_type("equity", "other")
+ name = "Goods Received Not Invoiced"
+ code = "grni"
+ self.account_grni = self._create_account(acc_type, name, code, self.company)
# Create account for Cost of Goods Sold
- acc_type = self._create_account_type('expense', 'other')
- name = 'Cost of Goods Sold'
- code = 'cogs'
- self.account_cogs = self._create_account(acc_type, name, code,
- self.company)
+ acc_type = self._create_account_type("expense", "other")
+ name = "Cost of Goods Sold"
+ code = "cogs"
+ self.account_cogs = self._create_account(acc_type, name, code, self.company)
# Create account for Inventory
- acc_type = self._create_account_type('asset', 'other')
- name = 'Inventory'
- code = 'inventory'
- self.account_inventory = self._create_account(acc_type, name, code,
- self.company)
+ acc_type = self._create_account_type("asset", "other")
+ name = "Inventory"
+ code = "inventory"
+ self.account_inventory = self._create_account(
+ acc_type, name, code, self.company
+ )
# Create Product
self.product = self._create_product()
# Create users
- self.sale_user = self._create_user('sale_user',
- [self.group_sale_user,
- self.group_account_invoice],
- self.company)
- self.account_invoice = self._create_user('account_invoice',
- [self.group_account_invoice],
- self.company)
- self.account_manager = self._create_user('account_manager',
- [self.group_account_manager],
- self.company)
+ self.sale_user = self._create_user(
+ "sale_user",
+ [self.group_sale_user, self.group_account_invoice],
+ self.company,
+ )
+ self.account_invoice = self._create_user(
+ "account_invoice", [self.group_account_invoice], self.company
+ )
+ self.account_manager = self._create_user(
+ "account_manager", [self.group_account_manager], self.company
+ )
def _create_user(self, login, groups, company):
""" Create a user."""
group_ids = [group.id for group in groups]
- user = \
- self.res_users_model.with_context(
- {'no_reset_password': True}).create({
- 'name': 'Test User',
- 'login': login,
- 'password': 'demo',
- 'email': 'test@yourcompany.com',
- 'company_id': company.id,
- 'company_ids': [(4, company.id)],
- 'groups_id': [(6, 0, group_ids)]
- })
+ user = self.res_users_model.with_context({"no_reset_password": True}).create(
+ {
+ "name": "Test User",
+ "login": login,
+ "password": "demo",
+ "email": "test@yourcompany.com",
+ "company_id": company.id,
+ "company_ids": [(4, company.id)],
+ "groups_id": [(6, 0, group_ids)],
+ }
+ )
return user.id
def _create_account_type(self, name, type):
- acc_type = self.acc_type_model.create({
- 'name': name,
- 'type': type
- })
+ acc_type = self.acc_type_model.create({"name": name, "type": type})
return acc_type
def _create_account(self, acc_type, name, code, company):
"""Create an account."""
- account = self.account_model.create({
- 'name': name,
- 'code': code,
- 'user_type_id': acc_type.id,
- 'company_id': company.id
- })
+ account = self.account_model.create(
+ {
+ "name": name,
+ "code": code,
+ "user_type_id": acc_type.id,
+ "company_id": company.id,
+ }
+ )
return account
def _create_product(self):
"""Create a Product."""
# group_ids = [group.id for group in groups]
- product_ctg = self.product_ctg_model.create({
- 'name': 'test_product_ctg',
- 'property_stock_valuation_account_id': self.account_inventory.id,
- 'property_valuation': 'real_time',
- '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,
- 'type': 'product',
- 'standard_price': 1.0,
- 'list_price': 1.0,
- })
+ product_ctg = self.product_ctg_model.create(
+ {
+ "name": "test_product_ctg",
+ "property_stock_valuation_account_id": self.account_inventory.id,
+ "property_valuation": "real_time",
+ "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,
+ "type": "product",
+ "standard_price": 1.0,
+ "list_price": 1.0,
+ }
+ )
return product
def _create_sale(self, line_products):
@@ -122,47 +122,46 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
lines = []
for product, qty in line_products:
line_values = {
- 'name': product.name,
- 'product_id': product.id,
- 'product_qty': qty,
- 'product_uom': product.uom_id.id,
- 'price_unit': 500,
- 'date_planned': fields.datetime.now()
+ "name": product.name,
+ "product_id": product.id,
+ "product_qty": qty,
+ "product_uom": product.uom_id.id,
+ "price_unit": 500,
+ "date_planned": fields.datetime.now(),
}
- lines.append(
- (0, 0, line_values)
- )
- return self.sale_model.create({
- 'partner_id': self.partner1.id,
- 'order_line': lines
- })
+ lines.append((0, 0, line_values))
+ return self.sale_model.create(
+ {"partner_id": self.partner1.id, "order_line": lines}
+ )
def _get_balance(self, domain):
"""
Call read_group method and return the balance of particular account.
"""
- aml_rec = self.aml_model.read_group(domain,
- ['debit', 'credit', 'account_id'],
- ['account_id'])
+ aml_rec = self.aml_model.read_group(
+ domain, ["debit", "credit", "account_id"], ["account_id"]
+ )
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:
return 0.0
- def _check_account_balance(self, account_id, sale_line=None,
- expected_balance=0.0):
+ def _check_account_balance(self, account_id, sale_line=None, expected_balance=0.0):
"""
Check the balance of the account
"""
- domain = [('account_id', '=', account_id)]
+ domain = [("account_id", "=", account_id)]
if sale_line:
- domain.extend([('sale_line_id', '=', sale_line.id)])
+ domain.extend([("sale_line_id", "=", sale_line.id)])
balance = self._get_balance(domain)
if sale_line:
- self.assertEqual(balance, expected_balance,
- 'Balance is not %s for sale Line %s.'
- % (str(expected_balance), sale_line.name))
+ self.assertEqual(
+ balance,
+ expected_balance,
+ "Balance is not %s for sale Line %s."
+ % (str(expected_balance), sale_line.name),
+ )
def test_sale_invoice(self):
"""Test that the po line moves from the sale order to the
@@ -176,35 +175,48 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
sale.button_confirm()
picking = sale.picking_ids[0]
picking.force_assign()
- picking.move_lines.write({'quantity_done': 1.0})
+ picking.move_lines.write({"quantity_done": 1.0})
picking.button_validate()
expected_balance = 1.0
- self._check_account_balance(self.account_inventory.id,
- sale_line=po_line,
- expected_balance=expected_balance)
+ self._check_account_balance(
+ self.account_inventory.id,
+ sale_line=po_line,
+ expected_balance=expected_balance,
+ )
- invoice = self.invoice_model.create({
- 'partner_id': self.partner1.id,
- 'sale_id': sale.id,
- 'account_id': sale.partner_id.property_account_payable_id.id,
- })
+ invoice = self.invoice_model.create(
+ {
+ "partner_id": self.partner1.id,
+ "sale_id": sale.id,
+ "account_id": sale.partner_id.property_account_payable_id.id,
+ }
+ )
invoice.sale_order_change()
invoice.action_invoice_open()
for aml in invoice.move_id.line_ids:
if aml.product_id == po_line.product_id and aml.invoice_id:
- self.assertEqual(aml.sale_line_id, po_line,
- 'sale Order line has not been copied '
- 'from the invoice to the account move line.')
+ self.assertEqual(
+ aml.sale_line_id,
+ po_line,
+ "sale Order line has not been copied "
+ "from the invoice to the account move line.",
+ )
def test_name_get(self):
sale = self._create_sale([(self.product, 1)])
po_line = sale.order_line[0]
- name_get = po_line.with_context({'po_line_info': True}).name_get()
- self.assertEqual(name_get, [(po_line.id, "[%s] %s (%s)" % (
- po_line.order_id.name, po_line.name,
- po_line.order_id.state,
- ))])
+ name_get = po_line.with_context({"po_line_info": True}).name_get()
+ self.assertEqual(
+ name_get,
+ [
+ (
+ 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()
self.assertEqual(name_get_no_ctx, [(po_line.id, po_line.name)])
diff --git a/account_move_line_sale_info/views/account_move_view.xml b/account_move_line_sale_info/views/account_move_view.xml
index 8fa88ec9..47541062 100644
--- a/account_move_line_sale_info/views/account_move_view.xml
+++ b/account_move_line_sale_info/views/account_move_view.xml
@@ -1,70 +1,89 @@
-
+
-
account.move.line.form
account.move.line
-
+
-
-
+
+
-
account.move.line.tree
account.move.line
-
+
-
-
+
+
-
-
Journal Items
account.move.line
-
+
-
-
+
+
-
-
+
+
-
-
account.move.form
account.move
-
+
-
-
-
+
+
+
-