[imp] make validity_date a real field, fix company relation, fix security groups
This commit is contained in:
parent
676215ad9c
commit
13c83e31c8
4 changed files with 58 additions and 26 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
from odoo import _, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,15 +42,21 @@ class SaleOrder(models.Model):
|
||||||
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
||||||
return super().action_confirm()
|
return super().action_confirm()
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
for vals in vals_list:
|
||||||
|
if vals.get("batch_id"):
|
||||||
|
vals["validity_date"] = (
|
||||||
|
self.env["sale.order.batch"].search([("id", "=", vals.get("batch_id"))]).validity_date
|
||||||
|
)
|
||||||
|
return super().create(vals_list)
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
if "batch_id" in vals:
|
if vals.get("batch_id"):
|
||||||
invalid_orders = []
|
vals["validity_date"] = (
|
||||||
for order in self:
|
self.env["sale.order.batch"].search([("id", "=", vals.get("batch_id"))]).validity_date
|
||||||
if order.state not in ["draft", "sent"]:
|
)
|
||||||
invalid_orders.append(order.name)
|
|
||||||
if invalid_orders:
|
|
||||||
raise UserError(_(f"Sale Order not in State Draft or Sent: {', '.join(invalid_orders)}"))
|
|
||||||
res = super().write(vals)
|
res = super().write(vals)
|
||||||
if "batch_id" in vals:
|
if vals.get("batch_id"):
|
||||||
self.order_line._update_batch_product()
|
self.order_line._update_batch_product()
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,19 @@
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
|
||||||
STATES = [("open", "Open"), ("close", "Close")]
|
STATES = [("open", "Open"), ("close", "Close")]
|
||||||
|
|
||||||
|
READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"close"}}
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderBatch(models.Model):
|
class SaleOrderBatch(models.Model):
|
||||||
"""Group serveral Sale Orders into a batch"""
|
"""Group serveral Sale Orders into a batch"""
|
||||||
|
|
||||||
_name = "sale.order.batch"
|
_name = "sale.order.batch"
|
||||||
_description = "Sale Order Batch"
|
_description = "Sales Order Batch"
|
||||||
_inherit = "mail.thread"
|
_inherit = ["mail.thread", "mail.activity.mixin"]
|
||||||
_order = "date_order desc, id desc"
|
_order = "date_order desc, id desc"
|
||||||
_check_company_auto = True
|
_check_company_auto = True
|
||||||
|
|
||||||
|
|
@ -42,7 +46,16 @@ class SaleOrderBatch(models.Model):
|
||||||
help="Creation date of order batch,\nConfirmation date of confirmed orders.",
|
help="Creation date of order batch,\nConfirmation date of confirmed orders.",
|
||||||
default=fields.Datetime.now,
|
default=fields.Datetime.now,
|
||||||
)
|
)
|
||||||
validity_date = fields.Date(compute="_compute_validity_date")
|
validity_date = fields.Date(
|
||||||
|
string="Expiration",
|
||||||
|
compute="_compute_validity_date",
|
||||||
|
inverse="_inverse_validity_date",
|
||||||
|
store=True,
|
||||||
|
readonly=False,
|
||||||
|
copy=False,
|
||||||
|
precompute=True,
|
||||||
|
states=READONLY_FIELD_STATES,
|
||||||
|
)
|
||||||
sale_order_ids = fields.One2many("sale.order", "batch_id")
|
sale_order_ids = fields.One2many("sale.order", "batch_id")
|
||||||
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
||||||
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True)
|
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True)
|
||||||
|
|
@ -53,14 +66,28 @@ class SaleOrderBatch(models.Model):
|
||||||
product_count = fields.Integer(compute="_compute_product_count")
|
product_count = fields.Integer(compute="_compute_product_count")
|
||||||
partner_credit_warning = fields.Text(compute="_compute_partner_credit_warning")
|
partner_credit_warning = fields.Text(compute="_compute_partner_credit_warning")
|
||||||
|
|
||||||
@api.depends("sale_order_ids.validity_date")
|
@api.depends("company_id")
|
||||||
def _compute_validity_date(self):
|
def _compute_validity_date(self):
|
||||||
|
enabled_feature = bool(self.env["ir.config_parameter"].sudo().get_param("sale.use_quotation_validity_days"))
|
||||||
|
if not enabled_feature:
|
||||||
|
self.validity_date = False
|
||||||
|
return
|
||||||
|
today = fields.Date.context_today(self)
|
||||||
for batch in self:
|
for batch in self:
|
||||||
if batch.sale_order_ids:
|
days = batch.company_id.quotation_validity_days
|
||||||
batch.validity_date = min(batch.sale_order_ids.mapped("validity_date"))
|
if days > 0:
|
||||||
|
batch.validity_date = today + timedelta(days)
|
||||||
else:
|
else:
|
||||||
batch.validity_date = False
|
batch.validity_date = False
|
||||||
|
|
||||||
|
def _inverse_validity_date(self):
|
||||||
|
"""
|
||||||
|
Set validity date on all Sale Orders
|
||||||
|
"""
|
||||||
|
for batch in self:
|
||||||
|
for order in batch.sale_order_ids:
|
||||||
|
order.validity_date = batch.validity_date
|
||||||
|
|
||||||
@api.depends("sale_order_ids.order_line")
|
@api.depends("sale_order_ids.order_line")
|
||||||
def _compute_sale_order_line_ids(self):
|
def _compute_sale_order_line_ids(self):
|
||||||
for batch in self:
|
for batch in self:
|
||||||
|
|
@ -136,8 +163,7 @@ class SaleOrderBatch(models.Model):
|
||||||
else:
|
else:
|
||||||
action = {"type": "ir.actions.act_window_close"}
|
action = {"type": "ir.actions.act_window_close"}
|
||||||
|
|
||||||
context = {"default_move_type": "out_invoice"}
|
action["context"] = {"default_move_type": "out_invoice"}
|
||||||
action["context"] = context
|
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
|
|
@ -153,12 +179,5 @@ class SaleOrderBatch(models.Model):
|
||||||
if "company_id" in vals:
|
if "company_id" in vals:
|
||||||
self = self.with_company(vals["company_id"])
|
self = self.with_company(vals["company_id"])
|
||||||
if vals.get("name", _("New")) == _("New"):
|
if vals.get("name", _("New")) == _("New"):
|
||||||
seq_date = (
|
vals["name"] = self.env["ir.sequence"].next_by_code("sale.order.batch") or _("New")
|
||||||
fields.Datetime.context_timestamp(self, fields.Datetime.to_datetime(vals["date_order"]))
|
|
||||||
if "date_order" in vals
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
vals["name"] = self.env["ir.sequence"].next_by_code("sale.order.batch", sequence_date=seq_date) or _(
|
|
||||||
"New"
|
|
||||||
)
|
|
||||||
return super().create(vals_list)
|
return super().create(vals_list)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_sale_order_batch_invoicing_payments,sale.order.batch,model_sale_order_batch,account.group_account_invoice,1,1,0,0
|
||||||
access_sale_order_batch,sale.order.batch,model_sale_order_batch,sales_team.group_sale_salesman,1,1,1,0
|
access_sale_order_batch,sale.order.batch,model_sale_order_batch,sales_team.group_sale_salesman,1,1,1,0
|
||||||
access_sale_order_batch_manager,sale.order.batch.manager,model_sale_order,sales_team.group_sale_manager,1,1,1,1
|
access_sale_order_batch_manager,sale.order.batch.manager,model_sale_order_batch,sales_team.group_sale_manager,1,1,1,1
|
||||||
access_sale_order_batch_product,sale.order.batch.product,model_sale_order_batch_product,sales_team.group_sale_salesman,1,1,1,1
|
access_sale_order_batch_product,sale.order.batch.product,model_sale_order_batch_product,sales_team.group_sale_salesman,1,1,1,1
|
||||||
|
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="date_order"/>
|
<field name="date_order"/>
|
||||||
<field name="validity_date" optional="hide"/>
|
<field name="validity_date" optional="hide"/>
|
||||||
|
<field name="company_id" groups="base.group_multi_company" optional="show" readonly="1"/>
|
||||||
|
<field name="company_id" groups="!base.group_multi_company" invisible="1"/>
|
||||||
<field name="sale_order_ids" widget="many2many_tags"/>
|
<field name="sale_order_ids" widget="many2many_tags"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
@ -91,6 +93,8 @@
|
||||||
<group>
|
<group>
|
||||||
<field name="date_order" attrs="{'readonly': [('state','=','closed')]}"/>
|
<field name="date_order" attrs="{'readonly': [('state','=','closed')]}"/>
|
||||||
<field name="validity_date" attrs="{'invisiable': [('state','=','closed')]}"/>
|
<field name="validity_date" attrs="{'invisiable': [('state','=','closed')]}"/>
|
||||||
|
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||||
|
<field name="company_id" invisible="1" groups="!base.group_multi_company"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
|
|
@ -105,6 +109,7 @@
|
||||||
<field name="date_order"/>
|
<field name="date_order"/>
|
||||||
<field name="amount_untaxed"/>
|
<field name="amount_untaxed"/>
|
||||||
<field name="amount_total"/>
|
<field name="amount_total"/>
|
||||||
|
<field name="company_id" invisible="1"/>
|
||||||
<field
|
<field
|
||||||
name="invoice_status"
|
name="invoice_status"
|
||||||
decoration-success="invoice_status == 'invoiced'"
|
decoration-success="invoice_status == 'invoiced'"
|
||||||
|
|
@ -129,6 +134,7 @@
|
||||||
<field name="product_template_id" optional="hide"/>
|
<field name="product_template_id" optional="hide"/>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
|
<field name="company_id" invisible="1"/>
|
||||||
<field name="price_unit"/>
|
<field name="price_unit"/>
|
||||||
<field name="price_subtotal"/>
|
<field name="price_subtotal"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue