2
0

forward port latest changes from 11.0

This commit is contained in:
Jordi Ballester Alomar 2019-07-29 12:32:21 +02:00 committed by Andrea Stirpe
parent 226b69a8a7
commit a9547f7535
7 changed files with 98 additions and 7 deletions

View File

@ -5,7 +5,7 @@
{
"name": "Account Move Line Purchase Info",
"summary": "Introduces the purchase order line to the journal items",
"version": "12.0.1.0.1",
"version": "12.0.2.0.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"website": "https://www.github.com/OCA/account-financial-tools",

View File

@ -0,0 +1,38 @@
# 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,5 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import account_move
from . import account_invoice
from . import purchase_order_line
from . import stock_move

View File

@ -14,3 +14,10 @@ class AccountMoveLine(models.Model):
string='Purchase Order Line',
ondelete='set null', index=True,
)
purchase_id = fields.Many2one(
comodel_name='purchase.order',
related='purchase_line_id.order_id',
string='Purchase Order',
store=True, index=True,
)

View File

@ -0,0 +1,20 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
@api.multi
def name_get(self):
result = []
orig_name = dict(super(PurchaseOrderLine, self).name_get())
for line in self:
name = orig_name[line.id]
if self.env.context.get('po_line_info', False):
name = "[%s] %s (%s)" % (line.order_id.name, name,
line.order_id.state)
result.append((line.id, name))
return result

View File

@ -199,3 +199,14 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
self.assertEqual(aml.purchase_line_id, po_line,
'Purchase Order line has not been copied '
'from the invoice to the account move line.')
def test_name_get(self):
purchase = self._create_purchase([(self.product, 1)])
po_line = purchase.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_no_ctx = po_line.name_get()
self.assertEqual(name_get_no_ctx, [(po_line.id, po_line.name)])

View File

@ -7,6 +7,8 @@
<field name="inherit_id" ref="account.view_move_line_form"/>
<field name="arch" type="xml">
<field name="quantity" position="before">
<field name="purchase_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<field name="purchase_line_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</field>
@ -19,6 +21,8 @@
<field name="inherit_id" ref="account.view_move_line_tree"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="purchase_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<field name="purchase_line_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</field>
@ -31,9 +35,19 @@
<field name="inherit_id" ref="account.view_account_move_line_filter"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="purchase_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<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>
<filter name="partner" position="after">
<filter name="purchase_order" string="Purchase Order" domain="[]"
context="{'group_by':'purchase_id'}"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<filter name="purchase_order_line" string="Purchase Order Line" domain="[]"
context="{'group_by':'purchase_line_id','po_line_info':True}"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</filter>
</field>
</record>
@ -43,9 +57,10 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath
expr="//field[@name='line_ids']/tree//field[@name='partner_id']" position="after">
<field name="purchase_line_id"
<xpath expr="//field[@name='line_ids']/tree//field[@name='partner_id']" position="after">
<field name="purchase_line_id" context="{'po_line_info': True}"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
<field name="purchase_id"
groups="account_move_line_purchase_info.group_account_move_purchase_info"/>
</xpath>
</field>