changes
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
@@ -96,46 +94,25 @@ class PurchaseOrder(models.Model):
|
||||
}
|
||||
|
||||
def action_fusion_match_sale_order(self):
|
||||
"""Match this PO to a Sale Order based on x_marked_for field."""
|
||||
"""Match this PO to a Sale Order based on the Marked For field."""
|
||||
self.ensure_one()
|
||||
|
||||
marked_for_value = getattr(self, 'x_marked_for', None)
|
||||
marked_for_value = self.fusion_marked_for_ids[:1] if self.fusion_marked_for_ids else None
|
||||
if not marked_for_value:
|
||||
return self._open_fusion_match_wizard('')
|
||||
|
||||
marked_for_str = str(marked_for_value)
|
||||
search_hint = marked_for_str
|
||||
matching_partners = None
|
||||
|
||||
partner_id_match = re.search(r'res\.partner\((\d+)', marked_for_str)
|
||||
if partner_id_match:
|
||||
partner_id = int(partner_id_match.group(1))
|
||||
partner = self.env['res.partner'].browse(partner_id).exists()
|
||||
if partner:
|
||||
matching_partners = partner
|
||||
search_hint = partner.name
|
||||
|
||||
if not matching_partners:
|
||||
matching_partners = self.env['res.partner'].search([
|
||||
'|',
|
||||
('name', 'ilike', marked_for_str),
|
||||
('display_name', 'ilike', marked_for_str),
|
||||
])
|
||||
|
||||
if not matching_partners:
|
||||
return self._open_fusion_match_wizard(search_hint)
|
||||
partner = marked_for_value
|
||||
search_hint = partner.name
|
||||
|
||||
matching_sales = self.env['sale.order'].search([
|
||||
('partner_id', 'in', matching_partners.ids),
|
||||
('partner_id', '=', partner.id),
|
||||
])
|
||||
|
||||
if not matching_sales or len(matching_sales) > 1:
|
||||
hint = matching_partners[0].name if matching_partners else search_hint
|
||||
return self._open_fusion_match_wizard(hint)
|
||||
return self._open_fusion_match_wizard(search_hint)
|
||||
|
||||
self.write({
|
||||
'fusion_sale_ids': [(4, matching_sales.id)],
|
||||
'fusion_marked_for_ids': [(4, matching_partners[0].id)],
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -150,53 +127,34 @@ class PurchaseOrder(models.Model):
|
||||
}
|
||||
|
||||
def action_fusion_batch_match(self):
|
||||
"""Batch match multiple POs to Sale Orders based on x_marked_for field."""
|
||||
"""Batch match multiple POs to Sale Orders based on Marked For field."""
|
||||
matched = 0
|
||||
skipped = 0
|
||||
errors = []
|
||||
|
||||
for po in self:
|
||||
marked_for_value = getattr(po, 'x_marked_for', None)
|
||||
if not marked_for_value:
|
||||
if not po.fusion_marked_for_ids:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
marked_for_str = str(marked_for_value)
|
||||
matching_partners = None
|
||||
|
||||
partner_id_match = re.search(r'res\.partner\((\d+)', marked_for_str)
|
||||
if partner_id_match:
|
||||
partner_id = int(partner_id_match.group(1))
|
||||
matching_partners = self.env['res.partner'].browse(partner_id).exists()
|
||||
|
||||
if not matching_partners:
|
||||
matching_partners = self.env['res.partner'].search([
|
||||
'|',
|
||||
('name', 'ilike', marked_for_str),
|
||||
('display_name', 'ilike', marked_for_str),
|
||||
])
|
||||
|
||||
if not matching_partners:
|
||||
errors.append(_("PO %s: No customer found for '%s'") % (po.name, marked_for_str))
|
||||
continue
|
||||
partner = po.fusion_marked_for_ids[:1]
|
||||
|
||||
matching_sales = self.env['sale.order'].search([
|
||||
('partner_id', 'in', matching_partners.ids),
|
||||
('partner_id', '=', partner.id),
|
||||
])
|
||||
|
||||
if not matching_sales:
|
||||
errors.append(_("PO %s: No SO found for '%s'") % (po.name, matching_partners[0].name))
|
||||
errors.append(_("PO %s: No SO found for '%s'") % (po.name, partner.name))
|
||||
continue
|
||||
|
||||
if len(matching_sales) > 1:
|
||||
errors.append(
|
||||
_("PO %s: Multiple SOs (%d) for '%s'") % (po.name, len(matching_sales), matching_partners[0].name)
|
||||
_("PO %s: Multiple SOs (%d) for '%s'") % (po.name, len(matching_sales), partner.name)
|
||||
)
|
||||
continue
|
||||
|
||||
po.write({
|
||||
'fusion_sale_ids': [(4, matching_sales.id)],
|
||||
'fusion_marked_for_ids': [(4, matching_partners[0].id)],
|
||||
})
|
||||
matched += 1
|
||||
|
||||
@@ -216,3 +174,13 @@ class PurchaseOrder(models.Model):
|
||||
'sticky': True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
x_fc_account_number = fields.Char(
|
||||
string='Account Number',
|
||||
tracking=True,
|
||||
help='Vendor/supplier account number',
|
||||
)
|
||||
|
||||
@@ -51,5 +51,29 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Purchase Order list: add Marked For column next to Vendor -->
|
||||
<record id="fusion_purchase_order_list_inherit" model="ir.ui.view">
|
||||
<field name="name">fusion.purchase.order.list.inherit</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="fusion_marked_for_ids" widget="many2many_tags" string="Marked For" optional="show"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- RFQ list: add Marked For column next to Vendor -->
|
||||
<record id="fusion_rfq_list_inherit" model="ir.ui.view">
|
||||
<field name="name">fusion.rfq.list.inherit</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_kpis_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="fusion_marked_for_ids" widget="many2many_tags" string="Marked For" optional="show"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user