[IMP] purchase: make products company consistence.

Purpose of the commit is to let user select only those
products which are being shared among companies or belongs to own company.

On purchase order user will only able to select those products
which are belongs to same company as purchase order or products
which are sharable by default.

task-2025168
closes: #34342

Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
Hetashree Chauhan
2019-07-22 05:17:00 +00:00
parent 421b9dfe21
commit e532d4df0d
2 changed files with 13 additions and 5 deletions
+9 -1
View File
@@ -8,7 +8,7 @@ from odoo import api, fields, models, SUPERUSER_ID, _
from odoo.osv import expression
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools.float_utils import float_compare
from odoo.exceptions import UserError, AccessError
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools.misc import formatLang
@@ -124,6 +124,14 @@ class PurchaseOrder(models.Model):
company_id = fields.Many2one('res.company', 'Company', required=True, index=True, states=READONLY_STATES, default=lambda self: self.env.company.id)
currency_rate = fields.Float("Currency Rate", compute='_compute_currency_rate', compute_sudo=True, store=True, readonly=True, help='Ratio between the purchase order currency and the company currency')
@api.constrains('company_id', 'order_line')
def _check_order_line_company_id(self):
for order in self:
companies = order.order_line.product_id.company_id
if companies and companies != order.company_id:
bad_products = order.order_line.product_id.filtered(lambda p: p.company_id and p.company_id != order.company_id)
raise ValidationError((_("Your quotation contains products from company %s whereas your quotation belongs to company %s. \n Please change the company of your quotation or remove the products from other companies (%s).") % (', '.join(companies.mapped('display_name')), order.company_id.display_name, ', '.join(bad_products.mapped('display_name')))))
def _compute_access_url(self):
super(PurchaseOrder, self)._compute_access_url()
for order in self:
+4 -4
View File
@@ -204,7 +204,7 @@
'required': [('display_type', '=', False)],
}"
context="{'partner_id':parent.partner_id, 'quantity':product_qty,'uom':product_uom, 'company_id': parent.company_id}"
force_save="1"/>
force_save="1" domain="[('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"/>
<field name="name" widget="section_and_note_text"/>
<field name="date_planned" optional="hide" attrs="{'required': [('display_type', '=', False)]}"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
@@ -232,9 +232,9 @@
<group>
<field name="product_uom_category_id" invisible="1"/>
<field name="product_id"
context="{'partner_id': parent.partner_id}"
widget="many2one_barcode"
attrs="{'required': [('display_type', '=', False)]}"
context="{'partner_id': parent.partner_id}"
widget="many2one_barcode"
domain="[('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
/>
<label for="product_qty"/>
<div class="o_row">