purchase_customer_requisition: removing agreement from a line recomputes pricing
This commit is contained in:
parent
1122f71628
commit
35e04f678c
4 changed files with 37 additions and 12 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
"purchase_requisition",
|
"purchase_requisition",
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
|
||||||
"views/purchase_views.xml",
|
"views/purchase_views.xml",
|
||||||
"views/purchase_requisition_views.xml",
|
"views/purchase_requisition_views.xml",
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
import logging
|
from odoo.addons.purchase.models.purchase_order_line import PurchaseOrderLine as BasePOL
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderLine(models.Model):
|
class PurchaseOrderLine(models.Model):
|
||||||
|
|
@ -28,6 +26,21 @@ class PurchaseOrderLine(models.Model):
|
||||||
line.price_unit = line.requisition_line_id.price_unit
|
line.price_unit = line.requisition_line_id.price_unit
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _compute_price_unit_and_date_planned_and_name(self):
|
||||||
|
super()._compute_price_unit_and_date_planned_and_name()
|
||||||
|
po_lines_with_requisition = self.filtered("requisition_id")
|
||||||
|
for line in po_lines_with_requisition:
|
||||||
|
line.price_unit = line.requisition_line_id.price_unit
|
||||||
|
po_lines_without_requisition = self - po_lines_with_requisition
|
||||||
|
to_compute_basic = self.env["purchase.order.line"]
|
||||||
|
for line in po_lines_without_requisition:
|
||||||
|
po_agreement_customers = line.order_id.requisition_id.customer_ids
|
||||||
|
customer = line._get_customer()
|
||||||
|
if po_agreement_customers and customer not in po_agreement_customers:
|
||||||
|
to_compute_basic |= line
|
||||||
|
func = BasePOL._compute_price_unit_and_date_planned_and_name
|
||||||
|
func(to_compute_basic)
|
||||||
|
|
||||||
@api.depends("requisition_id")
|
@api.depends("requisition_id")
|
||||||
def _compute_requisition_line_id(self):
|
def _compute_requisition_line_id(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
|
|
@ -39,11 +52,7 @@ class PurchaseOrderLine(models.Model):
|
||||||
@api.depends("order_id.requisition_id", "product_id")
|
@api.depends("order_id.requisition_id", "product_id")
|
||||||
def _compute_requisition_id(self):
|
def _compute_requisition_id(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
customer = line.sale_order_id.partner_id or line.group_id.partner_id
|
customer = self._get_customer()
|
||||||
if not customer:
|
|
||||||
sale_order = line.move_dest_ids.group_id.sale_id
|
|
||||||
if len(sale_order) == 1:
|
|
||||||
customer = sale_order.partner_id
|
|
||||||
domain = [
|
domain = [
|
||||||
"|",
|
"|",
|
||||||
("requisition_id.vendor_id", "=", line.order_id.partner_id.id),
|
("requisition_id.vendor_id", "=", line.order_id.partner_id.id),
|
||||||
|
|
@ -83,8 +92,17 @@ class PurchaseOrderLine(models.Model):
|
||||||
req_id = requisition_lines[0].requisition_id
|
req_id = requisition_lines[0].requisition_id
|
||||||
line.requisition_id = req_id
|
line.requisition_id = req_id
|
||||||
|
|
||||||
|
def _get_customer(self):
|
||||||
|
self.ensure_one()
|
||||||
|
customer = self.sale_order_id.partner_id or self.group_id.partner_id
|
||||||
|
if not customer:
|
||||||
|
sale_order = self.move_dest_ids.group_id.sale_id
|
||||||
|
if len(sale_order) == 1:
|
||||||
|
customer = sale_order.partner_id
|
||||||
|
return customer
|
||||||
|
|
||||||
def _inverse_requisition_id(self):
|
def _inverse_requisition_id(self):
|
||||||
pass
|
self._compute_price_unit_and_date_planned_and_name()
|
||||||
|
|
||||||
def _find_candidate(
|
def _find_candidate(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from odoo.addons.sale_purchase_inter_company_rules.models.purchase_order import (
|
from odoo.addons.sale_purchase_inter_company_rules.models.purchase_order import (
|
||||||
purchase_order,
|
purchase_order,
|
||||||
)
|
)
|
||||||
from odoo.tests import TransactionCase, tagged
|
from odoo.tests import TransactionCase, tagged, Form
|
||||||
from odoo import Command, fields
|
from odoo import Command, fields
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
@ -169,3 +169,12 @@ class TestPurchaseOrder(TransactionCase):
|
||||||
|
|
||||||
self.assertEqual(purchase_order.order_line[0].price_unit, 1000)
|
self.assertEqual(purchase_order.order_line[0].price_unit, 1000)
|
||||||
self.assertEqual(purchase_order.order_line[1].price_unit, 1500)
|
self.assertEqual(purchase_order.order_line[1].price_unit, 1500)
|
||||||
|
|
||||||
|
def test_removing_line_agreement_recomputes_pricing(self):
|
||||||
|
purchase_order = self._generate_2_sales_1_purchase_clients_1_3()
|
||||||
|
purchase_order.requisition_id = False
|
||||||
|
|
||||||
|
line = purchase_order.order_line[0]
|
||||||
|
line.requisition_id = False
|
||||||
|
|
||||||
|
self.assertEqual(purchase_order.order_line[0].price_unit, 3000)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue