This commit is contained in:
gsinghpal
2026-03-09 15:21:22 -04:00
parent a3e85a23ef
commit acd3fc455e
243 changed files with 20459 additions and 4197 deletions

View File

@@ -0,0 +1 @@
from . import save_as_template_wizard

View File

@@ -0,0 +1,88 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class SaveAsTemplateWizard(models.TransientModel):
_name = 'sale.order.save.template.wizard'
_description = 'Save Sale Order as Template'
sale_order_id = fields.Many2one(
'sale.order',
string='Sale Order',
required=True,
readonly=True,
)
template_name = fields.Char(
string='Template Name',
required=True,
)
note = fields.Html(
string='Terms and Conditions',
)
number_of_days = fields.Integer(
string='Quotation Duration (days)',
help='Number of days for the validity of quotations using this template.',
)
@api.onchange('sale_order_id')
def _onchange_sale_order_id(self):
if self.sale_order_id:
self.template_name = _('Template from %s', self.sale_order_id.name)
def action_save_as_template(self):
"""Create a sale.order.template from the linked sale order."""
self.ensure_one()
order = self.sale_order_id
if not order.order_line:
raise UserError(_('Cannot create a template from an order with no lines.'))
# Build template line values from sale order lines
template_line_vals = []
for sequence, line in enumerate(order.order_line, start=1):
vals = {
'sequence': sequence * 10,
}
if line.display_type == 'line_section':
vals.update({
'display_type': 'line_section',
'name': line.name or '',
})
elif line.display_type == 'line_note':
vals.update({
'display_type': 'line_note',
'name': line.name or '',
})
else:
vals.update({
'product_id': line.product_id.id,
'name': line.name or line.product_id.name,
'product_uom_qty': line.product_uom_qty,
'product_uom_id': line.product_uom_id.id if line.product_uom_id else False,
})
template_line_vals.append((0, 0, vals))
# Create the template
template_vals = {
'name': self.template_name,
'sale_order_template_line_ids': template_line_vals,
}
if self.note:
template_vals['note'] = self.note
if self.number_of_days:
template_vals['number_of_days'] = self.number_of_days
template = self.env['sale.order.template'].create(template_vals)
# Return action to open the created template
return {
'name': _('Quotation Template'),
'type': 'ir.actions.act_window',
'res_model': 'sale.order.template',
'res_id': template.id,
'view_mode': 'form',
'target': 'current',
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="save_as_template_wizard_form" model="ir.ui.view">
<field name="name">sale.order.save.template.wizard.form</field>
<field name="model">sale.order.save.template.wizard</field>
<field name="arch" type="xml">
<form string="Save as Template">
<group>
<field name="sale_order_id" invisible="1"/>
<field name="template_name" placeholder="e.g. Standard IT Equipment Package"/>
<field name="number_of_days"/>
<field name="note" placeholder="Optional terms and conditions..."/>
</group>
<footer>
<button name="action_save_as_template"
type="object"
string="Save Template"
class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>