Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mcfix_purchase/models/purchase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from odoo import api, models, _
from odoo import api, models, fields, _
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -137,6 +137,17 @@ def _check_company_id(self):
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

company_id = fields.Many2one(
'res.company', related=[], compute='_compute_line_company',
string='Company', store=True, readonly=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't put the unchanged attributes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is changed - it used to be related, it is now computed....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but you don't need to put again 'res.company', string, store, ...


@api.depends('order_id', 'order_id.company_id')
def _compute_line_company(self):
for line in self:
line.company_id = line.order_id.company_id
if not line.order_id and 'default_company_id' in self.env.context:
line.company_id = self.env.context['default_company_id']

@api.multi
@api.depends('company_id')
def name_get(self):
Expand Down
28 changes: 26 additions & 2 deletions mcfix_purchase/views/purchase_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@
<field name="payment_term_id" position="attributes">
<attribute name="domain">[('company_id', '=', company_id)]</attribute>
</field>
<field name="taxes_id" position="attributes">

<field name='order_line' position="attributes">
<attribute name="context">{"default_company_id": company_id}</attribute>
</field>
<xpath expr='//field[@name="order_line"]/tree//field[@name="taxes_id"]' position='attributes'>
<attribute name="domain">[('company_id', '=', company_id),('type_tax_use','=','purchase')]</attribute>
</xpath>
<xpath expr='//field[@name="order_line"]/form//field[@name="taxes_id"]' position='attributes'>
<attribute name="domain">[('company_id', '=', company_id),('type_tax_use','=','purchase')]</attribute>
</xpath>
<xpath expr='//field[@name="order_line"]/tree//field[@name="product_id"]' position='attributes'>
<attribute name="domain">['|', ('company_id', '=', company_id),('company_id', '=', False)]</attribute>
</xpath>
<xpath expr='//field[@name="order_line"]/form//field[@name="product_id"]' position='attributes'>
<attribute name="domain">['|', ('company_id', '=', company_id),('company_id', '=', False)]</attribute>
</xpath>
</field>
</record>

<record id="purchase_order_line_form2" model="ir.ui.view">
<field name="name">purchase.order.line.form2</field>
<field name="model">purchase.order.line</field>
<field name="inherit_id" ref="purchase.purchase_order_line_form2"/>
<field name="arch" type="xml">
<field name='taxes_id' position='attributes'>
<attribute name='domain'>[('type_tax_use','=','purchase'), ('company_id', '=', company_id)]</attribute>
</field>
<field name="product_id" position="attributes">
<field name='product_id' position='attributes'>
<attribute name="domain">['|', ('company_id', '=', company_id),('company_id', '=', False)]</attribute>
</field>
</field>
Expand Down