2
0

[MIG] account_move_line_purchase_info: Migration to 13.0

This commit is contained in:
Adrià Gil Sorribes 2019-12-24 10:29:45 +01:00 committed by Andrea Stirpe
parent 438d620eb6
commit 9d3033960c
12 changed files with 48 additions and 124 deletions

View File

@ -14,13 +14,13 @@ Account Move Line Purchase Info
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/12.0/account_move_line_purchase_info :target: https://github.com/OCA/account-financial-tools/tree/13.0/account_move_line_purchase_info
:alt: OCA/account-financial-tools :alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-12-0/account-financial-tools-12-0-account_move_line_purchase_info :target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_move_line_purchase_info
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/12.0 :target: https://runbot.odoo-community.org/runbot/92/13.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -52,7 +52,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_purchase_info%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_purchase_info%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -62,12 +62,12 @@ Credits
Authors Authors
~~~~~~~ ~~~~~~~
* Eficent * ForgeFlow
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Jordi Ballester Alomar <jordi.ballester@eficent.com> * Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -82,6 +82,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/12.0/account_move_line_purchase_info>`_ project on GitHub. This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/13.0/account_move_line_purchase_info>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,12 +1,12 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2019 ForgeFlow S.L.
# (www.eficent.com) # (https://www.forgeflow.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).
{ {
"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": "13.0.1.0.0",
"author": "Eficent, " "Odoo Community Association (OCA)", "author": "ForgeFlow, 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"],

View File

@ -1,40 +0,0 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
_logger = logging.getLogger(__name__)
__name__ = "Upgrade to 12.0.2.0.0"
def update_purchase_id_column(cr):
cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='account_move_line' AND
column_name='purchase_id'"""
)
if not cr.fetchone():
_logger.info("""Add column purchase_id to account_move_line""")
cr.execute(
"""
ALTER TABLE account_move_line ADD COLUMN purchase_id integer;
"""
)
_logger.info("""Updating values for purchase_id in account_move_line""")
cr.execute(
"""
UPDATE account_move_line aml
SET purchase_id = pol.order_id
FROM purchase_order_line AS pol
WHERE aml.purchase_line_id = pol.id
"""
)
def migrate(cr, version):
if not version:
return
update_purchase_id_column(cr)

View File

@ -1,4 +1,3 @@
from . import account_move from . import account_move
from . import account_invoice
from . import purchase_order_line from . import purchase_order_line
from . import stock_move from . import stock_move

View File

@ -1,29 +0,0 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class AccountInvoice(models.Model):
_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"]
for move_line_dict in res:
if "invl_id" in move_line_dict:
line = invoice_line_model.browse(move_line_dict["invl_id"])
move_line_dict["purchase_line_id"] = line.purchase_line_id.id
return res
@api.model
def line_get_convert(self, line, part):
res = super(AccountInvoice, self).line_get_convert(line, part)
if line.get("purchase_line_id", False):
res["purchase_line_id"] = line.get("purchase_line_id")
return res

View File

@ -1,5 +1,5 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2019 ForgeFlow S.L.
# (www.eficent.com) # (https://www.forgeflow.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 import fields, models from odoo import fields, models
@ -9,13 +9,6 @@ class AccountMoveLine(models.Model):
_inherit = "account.move.line" _inherit = "account.move.line"
purchase_line_id = fields.Many2one(
comodel_name="purchase.order.line",
string="Purchase Order Line",
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",

View File

@ -1,19 +1,21 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L. # Copyright 2019 ForgeFlow S.L.
# (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, models from odoo import models
class PurchaseOrderLine(models.Model): class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line" _inherit = "purchase.order.line"
@api.multi
def name_get(self): def name_get(self):
result = [] result = []
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 = "[{}] {} ({})".format(line.order_id.name, name, line.order_id.state) name = "[{}] {} ({})".format(
line.order_id.name, name, line.order_id.state
)
result.append((line.id, name)) result.append((line.id, name))
return result return result

View File

@ -1,5 +1,5 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2019 ForgeFlow S.L.
# (www.eficent.com) # (https://www.forgeflow.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 import api, models from odoo import api, models
@ -10,10 +10,10 @@ class StockMove(models.Model):
@api.model @api.model
def _prepare_account_move_line( def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id self, qty, cost, credit_account_id, debit_account_id, description
): ):
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, description
) )
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

View File

@ -1 +1 @@
* Jordi Ballester Alomar <jordi.ballester@eficent.com> * Jordi Ballester Alomar <jordi.ballester@forgeflow.com>

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/12.0/account_move_line_purchase_info"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-12-0/account-financial-tools-12-0-account_move_line_purchase_info"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/13.0/account_move_line_purchase_info"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_move_line_purchase_info"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module will add the purchase order line to journal items.</p> <p>This module will add the purchase order line to journal items.</p>
<p>The ultimate goal is to establish the purchase order line as one of the key <p>The ultimate goal is to establish the purchase order line as one of the key
fields to reconcile the Goods Received Not Invoiced accrual account.</p> fields to reconcile the Goods Received Not Invoiced accrual account.</p>
@ -399,7 +399,7 @@ order line is copied to the account move line.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_purchase_info%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_purchase_info%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -407,13 +407,13 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<div class="section" id="authors"> <div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2> <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Eficent</li> <li>ForgeFlow</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2> <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li> <li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;forgeflow.com">jordi.ballester&#64;forgeflow.com</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -423,7 +423,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/12.0/account_move_line_purchase_info">OCA/account-financial-tools</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/13.0/account_move_line_purchase_info">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -1,9 +1,9 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2019 ForgeFlow S.L.
# (www.eficent.com) # (https://www.forgeflow.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 import fields from odoo import fields
from odoo.tests import common from odoo.tests import Form, common
class TestAccountMoveLinePurchaseInfo(common.TransactionCase): class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
@ -11,12 +11,11 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
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_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.am_model = self.env["account.move"]
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"]
@ -78,7 +77,9 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
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({"name": name, "type": type}) acc_type = self.acc_type_model.create(
{"name": name, "type": type, "internal_group": name}
)
return acc_type return acc_type
def _create_account(self, acc_type, name, code, company): def _create_account(self, acc_type, name, code, company):
@ -89,6 +90,7 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
"code": code, "code": code,
"user_type_id": acc_type.id, "user_type_id": acc_type.id,
"company_id": company.id, "company_id": company.id,
"reconcile": True,
} }
) )
return account return account
@ -189,18 +191,15 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
expected_balance=expected_balance, expected_balance=expected_balance,
) )
invoice = self.invoice_model.create( f = Form(self.am_model.with_context(default_type="in_invoice"))
{ f.partner_id = purchase.partner_id
"partner_id": self.partner1.id, f.purchase_id = purchase
"purchase_id": purchase.id, invoice = f.save()
"account_id": purchase.partner_id.property_account_payable_id.id, invoice.post()
} purchase.flush()
)
invoice.purchase_order_change()
invoice.action_invoice_open()
for aml in invoice.move_id.line_ids: for aml in invoice.invoice_line_ids:
if aml.product_id == po_line.product_id and aml.invoice_id: if aml.product_id == po_line.product_id and aml.move_id:
self.assertEqual( self.assertEqual(
aml.purchase_line_id, aml.purchase_line_id,
po_line, po_line,

View File

@ -40,11 +40,11 @@
<field name="purchase_line_id" <field name="purchase_line_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/> groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</field> </field>
<filter name="partner" position="after"> <filter name="group_by_partner" position="after">
<filter name="purchase_order" string="Purchase Order" domain="[]" <filter name="group_by_purchase_order" string="Purchase Order" domain="[]"
context="{'group_by':'purchase_id'}" context="{'group_by':'purchase_id'}"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/> groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<filter name="purchase_order_line" string="Purchase Order Line" domain="[]" <filter name="group_by_purchase_order_line" string="Purchase Order Line" domain="[]"
context="{'group_by':'purchase_line_id','po_line_info':True}" context="{'group_by':'purchase_line_id','po_line_info':True}"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/> groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</filter> </filter>