mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 09:52:02 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -4,28 +4,12 @@
|
|||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class SupplierInfo(models.Model):
|
||||
_name = "product.supplierinfo"
|
||||
class ProductSupplierinfo(models.Model):
|
||||
_name = 'product.supplierinfo'
|
||||
_description = "Supplier Pricelist"
|
||||
_order = 'sequence, min_qty DESC, price, id'
|
||||
_rec_name = 'partner_id'
|
||||
|
||||
def _default_product_id(self):
|
||||
product_id = self.env.get('default_product_id')
|
||||
if not product_id:
|
||||
model, active_id = [self.env.context.get(k) for k in ['model', 'active_id']]
|
||||
if model == 'product.product' and active_id:
|
||||
product_id = self.env[model].browse(active_id).exists()
|
||||
return product_id
|
||||
|
||||
def _domain_product_id(self):
|
||||
domain = "product_tmpl_id and [('product_tmpl_id', '=', product_tmpl_id)] or []"
|
||||
if self.env.context.get('base_model_name') == 'product.template':
|
||||
domain = "[('product_tmpl_id', '=', parent.id)]"
|
||||
elif self.env.context.get('base_model_name') == 'product.product':
|
||||
domain = "[('product_tmpl_id', '=', parent.product_tmpl_id)]"
|
||||
return domain
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
'res.partner', 'Vendor',
|
||||
ondelete='cascade', required=True,
|
||||
|
|
@ -38,15 +22,14 @@ class SupplierInfo(models.Model):
|
|||
help="This vendor's product code will be used when printing a request for quotation. Keep empty to use the internal one.")
|
||||
sequence = fields.Integer(
|
||||
'Sequence', default=1, help="Assigns the priority to the list of product vendor.")
|
||||
product_uom = fields.Many2one(
|
||||
'uom.uom', 'Unit of Measure',
|
||||
related='product_tmpl_id.uom_po_id')
|
||||
product_uom_id = fields.Many2one(
|
||||
'uom.uom', 'Unit', compute='_compute_product_uom_id', store=True, readonly=False, required=True, precompute=True)
|
||||
min_qty = fields.Float(
|
||||
'Quantity', default=0.0, required=True, digits="Product Unit of Measure",
|
||||
help="The quantity to purchase from this vendor to benefit from the price, expressed in the vendor Product Unit of Measure if not any, in the default unit of measure of the product otherwise.")
|
||||
'Quantity', default=0.0, required=True, digits="Product Unit",
|
||||
help="The quantity to purchase from this vendor to benefit from the unit price. If a vendor unit is set, quantity should be specified in this unit, otherwise it should be specified in the default unit of the product.")
|
||||
price = fields.Float(
|
||||
'Price', default=0.0, digits='Product Price',
|
||||
required=True, help="The price to purchase a product")
|
||||
'Unit Price', min_display_digits='Product Price', default=0.0, help="The price to purchase a product")
|
||||
price_discounted = fields.Float('Discounted Price', compute='_compute_price_discounted')
|
||||
company_id = fields.Many2one(
|
||||
'res.company', 'Company',
|
||||
default=lambda self: self.env.company.id, index=1)
|
||||
|
|
@ -58,15 +41,49 @@ class SupplierInfo(models.Model):
|
|||
date_end = fields.Date('End Date', help="End date for this vendor price")
|
||||
product_id = fields.Many2one(
|
||||
'product.product', 'Product Variant', check_company=True,
|
||||
domain=_domain_product_id, default=_default_product_id,
|
||||
domain="[('product_tmpl_id', '=', product_tmpl_id)] if product_tmpl_id else []",
|
||||
compute='_compute_product_id', store=True, readonly=False, precompute=True,
|
||||
help="If not set, the vendor price will apply to all variants of this product.")
|
||||
product_tmpl_id = fields.Many2one(
|
||||
'product.template', 'Product Template', check_company=True,
|
||||
index=True, ondelete='cascade')
|
||||
'product.template', 'Product Template', check_company=True, compute='_compute_product_tmpl_id', precompute=True,
|
||||
store=True, readonly=False, required=True, index=True, ondelete='cascade')
|
||||
product_variant_count = fields.Integer('Variant Count', related='product_tmpl_id.product_variant_count')
|
||||
delay = fields.Integer(
|
||||
'Delivery Lead Time', default=1, required=True,
|
||||
'Lead Time', default=1, required=True,
|
||||
help="Lead time in days between the confirmation of the purchase order and the receipt of the products in your warehouse. Used by the scheduler for automatic computation of the purchase order planning.")
|
||||
discount = fields.Float(
|
||||
string="Discount (%)",
|
||||
digits='Discount',
|
||||
readonly=False)
|
||||
|
||||
@api.depends('product_id', 'product_tmpl_id')
|
||||
def _compute_product_uom_id(self):
|
||||
for rec in self:
|
||||
if not rec.product_uom_id:
|
||||
rec.product_uom_id = rec.product_id.uom_id if rec.product_id else rec.product_tmpl_id.uom_id
|
||||
|
||||
@api.depends('product_id', 'product_tmpl_id')
|
||||
def _compute_price(self):
|
||||
for rec in self:
|
||||
rec.price = rec.product_id.standard_price if rec.product_id else rec.product_tmpl_id.standard_price if rec.product_tmpl_id else 0.0
|
||||
|
||||
@api.depends('discount', 'price')
|
||||
def _compute_price_discounted(self):
|
||||
for rec in self:
|
||||
product_uom = (rec.product_id or rec.product_tmpl_id).uom_id
|
||||
rec.price_discounted = rec.product_uom_id._compute_price(rec.price, product_uom) * (1 - rec.discount / 100)
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_product_tmpl_id(self):
|
||||
for rec in self:
|
||||
if rec.product_id:
|
||||
rec.product_tmpl_id = rec.product_id.product_tmpl_id
|
||||
|
||||
@api.depends('product_id', 'product_tmpl_id', 'product_variant_count')
|
||||
def _compute_product_id(self):
|
||||
for rec in self:
|
||||
if self.env.get('default_product_id'):
|
||||
rec.product_id = self.env.get('default_product_id')
|
||||
|
||||
@api.onchange('product_tmpl_id')
|
||||
def _onchange_product_tmpl_id(self):
|
||||
|
|
@ -97,3 +114,6 @@ class SupplierInfo(models.Model):
|
|||
def write(self, vals):
|
||||
self._sanitize_vals(vals)
|
||||
return super().write(vals)
|
||||
|
||||
def _get_filtered_supplier(self, company_id, product_id, params=False):
|
||||
return self.filtered(lambda s: (not s.company_id or s.company_id.id == company_id.id) and (s.partner_id.active and (not s.product_id or s.product_id == product_id)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue