diff --git a/custom_fields/__init__.py b/custom_fields/__init__.py
index e69de29bb..9a7e03ede 100644
--- a/custom_fields/__init__.py
+++ b/custom_fields/__init__.py
@@ -0,0 +1 @@
+from . import models
\ No newline at end of file
diff --git a/custom_fields/__manifest__.py b/custom_fields/__manifest__.py
index 6d0c83768..f68cdc70c 100644
--- a/custom_fields/__manifest__.py
+++ b/custom_fields/__manifest__.py
@@ -1,15 +1,16 @@
{
- 'name': 'Deal Eligible Management',
+ 'name': 'Custom sale and invoice fields',
'version': '1.0',
'summary': 'Module to manage deal eligibles',
'description': 'Custom module for managing deals and their details in Sales Management.',
'author': 'Your Name',
'website': 'https://yourwebsite.com',
'category': 'Sales',
- 'depends': ['base', 'sale', 'account'],
+ 'depends': ['base', 'sale', 'account','purchase',],
'data': [
'security/ir.model.access.csv',
- 'views/deal_eligible_views.xml',
+ 'views/sale_order_views.xml',
+ 'views/account_move_views',
],
'installable': True,
'application': True,
diff --git a/custom_fields/models/__init__.py b/custom_fields/models/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/custom_fields/models/account_move.py b/custom_fields/models/account_move.py
new file mode 100644
index 000000000..f5a26dd30
--- /dev/null
+++ b/custom_fields/models/account_move.py
@@ -0,0 +1,61 @@
+from odoo import api, fields, models
+
+class AccountMove(models.Model):
+ _inherit = 'account.move'
+
+ booking_date = fields.Date(
+ string='Booking Date',
+ tracking=False,
+ )
+
+ developer_commission = fields.Float(
+ string='Broker Commission',
+ tracking=True,
+ )
+
+ buyer = fields.Many2one(
+ 'res.partner',
+ string='Buyer Name',
+ tracking=True,
+ )
+
+ deal_id = fields.Integer(
+ string='Deal ID',
+ tracking=True,
+ )
+
+ project = fields.Many2one(
+ 'product.template',
+ string='Project Name',
+ tracking=True,
+ )
+
+ sale_value = fields.Monetary(
+ string='Sale Value',
+ tracking=True,
+ )
+
+ unit = fields.Many2one(
+ 'product.product',
+ string='Unit',
+ tracking=True,
+ )
+
+ @api.model
+ def create(self, vals):
+ # Check if invoice is created from sale order
+ if vals.get('move_type') in ['out_invoice', 'out_refund'] and vals.get('invoice_origin'):
+ sale_order = self.env['sale.order'].search([
+ ('name', '=', vals.get('invoice_origin'))
+ ], limit=1)
+ if sale_order:
+ vals.update({
+ 'booking_date': sale_order.booking_date,
+ 'developer_commission': sale_order.developer_commission,
+ 'buyer': sale_order.buyer.id if sale_order.buyer else False,
+ 'deal_id': sale_order.deal_id,
+ 'project': sale_order.project.id if sale_order.project else False,
+ 'sale_value': sale_order.sale_value,
+ 'unit': sale_order.unit.id if sale_order.unit else False,
+ })
+ return super(AccountMove, self).create(vals)
\ No newline at end of file
diff --git a/custom_fields/models/custom_fields.py b/custom_fields/models/custom_fields.py
deleted file mode 100644
index 2fb86e998..000000000
--- a/custom_fields/models/custom_fields.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from odoo import models, fields, api
-
-class DealEligible(models.Model):
- _name = 'deal.eligible'
- _description = 'Deal Eligible'
-
- booking_date = fields.Date(string="Booking Date")
- developer_commission = fields.Float(string="Broker Commission", tracking=True)
- buyer = fields.Many2one('res.partner', string="Buyer Name", tracking=True)
- deal_id = fields.Integer(string="Deal ID", tracking=True)
- project = fields.Many2one('product.template', string="Project Name", tracking=True)
- sale_value = fields.Monetary(string="Sale Value", tracking=True, currency_field='currency_id')
- unit = fields.Many2one('product.product', string="Unit", tracking=True)
- currency_id = fields.Many2one('res.currency', string="Currency")
\ No newline at end of file
diff --git a/custom_fields/models/sale_order.py b/custom_fields/models/sale_order.py
new file mode 100644
index 000000000..4be519b8c
--- /dev/null
+++ b/custom_fields/models/sale_order.py
@@ -0,0 +1,54 @@
+from odoo import models, fields, api
+from odoo.exceptions import ValidationError
+
+class SaleOrder(models.Model):
+ _inherit = 'sale.order'
+
+ # Custom fields for deal tracking
+ booking_date = fields.Date(
+ string='Booking Date',
+ tracking=True,
+ )
+
+ developer_commission = fields.Float(
+ string='Broker Commission',
+ tracking=True,
+ digits=(16, 2),
+ )
+
+ buyer_id = fields.Many2one(
+ 'res.partner',
+ string='Buyer',
+ tracking=True,
+ )
+
+ deal_id = fields.Integer(
+ string='Deal ID',
+ tracking=True,
+ copy=False, # Don't copy when duplicating record
+ )
+
+ project_id = fields.Many2one(
+ 'product.template',
+ string='Project Name',
+ tracking=True,
+ )
+
+ sale_value = fields.Monetary(
+ string='Sale Value',
+ tracking=True,
+ currency_field='currency_id',
+ )
+
+ unit_id = fields.Many2one(
+ 'product.product',
+ string='Unit',
+ tracking=True,
+ domain="[('product_tmpl_id', '=', project_id)]", # Only show units related to selected project
+ )
+
+ @api.onchange('project_id')
+ def _onchange_project_id(self):
+ """Clear unit selection when project changes"""
+ if self.project_id:
+ self.unit_id = False
\ No newline at end of file
diff --git a/custom_fields/views/account_move_views.xml b/custom_fields/views/account_move_views.xml
new file mode 100644
index 000000000..f9211233f
--- /dev/null
+++ b/custom_fields/views/account_move_views.xml
@@ -0,0 +1,26 @@
+
+
+
+
+ account.move.form.inherit.custom.fields
+ account.move
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/custom_fields/views/custom_sale_fields_views.xml b/custom_fields/views/custom_sale_fields_views.xml
deleted file mode 100644
index 595e7acf3..000000000
--- a/custom_fields/views/custom_sale_fields_views.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
- deal.eligible.tree
- deal.eligible
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- deal.eligible.form
- deal.eligible
-
-
-
-
-
-
-
-
-
-
- Deal Eligibles
- deal.eligible
- tree,form
-
-
-'''
diff --git a/custom_fields/views/sale_order_views.xml b/custom_fields/views/sale_order_views.xml
new file mode 100644
index 000000000..4db8bb31f
--- /dev/null
+++ b/custom_fields/views/sale_order_views.xml
@@ -0,0 +1,21 @@
+
+
+
+ sale.order.form.deal.tracking
+ sale.order
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file