Contributors mailing list archives
contributors@odoo-community.org
Browse archives
Re: Receiving in the Purchase UoM
byHi Stefano,
I could but currently don't have time (esp. to create tests). So here's the contents of what I did if you wanted to go and create PR yourself. It allows you to either ent factor or factor_inv and the other gets recomputed:
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ProductSecondaryUnit(models.Model):
_inherit = "product.secondary.unit"
factor_inv = fields.Float(
"Secondary Unit Factor Inv.",
compute="_compute_factor_inv",
inverse="_set_factor_inv",
)
@api.depends("factor")
def _compute_factor_inv(self):
for unit in self:
if unit.factor == 0:
raise ValidationError(_("The value of factor could not be Zero"))
else:
unit.factor_inv = 1 / unit.factor
def _set_factor_inv(self):
for unit in self:
if unit.factor_inv == 0:
raise ValidationError(
_("The value of inversed factor could not be Zero")
)
else:
unit.factor = 1 / unit.factor_inv
And you just add the factor_inv into view:
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">Product template Secondary Unit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='secondary_uom_ids']/tree/field[@name='uom_id']" position="before">
<field name="factor_inv"/>
</xpath>
</field>
</record>
Best regards
Radovan
On pondelok 11. marca 2024 8:26:54 CET Stefano Consolaro wrote:
> Hi Radovan, do you think that the "small module" for product_secondary_unit
> can be refactored as a configuration options? If so, can you do a PR fot
> it? Thanks Stefano
> Da "Radovan Skolnik" notifications@odoo-community.org
> A "Contributors" contributors@odoo-community.org
> Cc
> Data Sat, 09 Mar 2024 15:38:21 -0000
> Oggetto Re: Receiving in the Purchase UoM
>
> Hi,
>
> I was dealing with this just recently. What works (although it's not 100%
> what yo want) is using those 2 modules:
>
> product_secondary_unit - allows you to add secondary UoM(s) with their
> factor - i.e. you add secondary UoM of kg with conversion factor of 1/1.26
> (this seems a bit awkward but it's inverted - I have created a small module
> to be able to add inverse factor of 1.26 and ocmpute the original factor)
> stock_secondary_unit - this basically allows you to choose one of the
> product's secondary UoM to show (besides qty in original UoM) qty on hand
> as well as in stock moves. Actually in stock moves it does not work - see
> https://github.com/OCA/stock-logistics-warehouse/pull/1769 [1] for my
> proposal to fix it.
>
> Best regards
>
> Radovan
>
> On sobota 9. marca 2024 16:27:22 CET Daniel Reis wrote:
> > Hello, maybe some of you came across this need:
> > I keep my Glycerine stock in Kg.
> > My supplier sells it in Liters.
> > I know that the density of Glycerine is 1.26, so 1 Liter = 1.26 Kg.
> > I would like to:
> > 1. Send a Purchase Order for 100 Liters.
> > 2. Receive from the Supplier the 100 Liters delivered.
> > 3. View my stock as 126 Kg.
> > Setting a Purchase UoM works for 1. and 3., but does not work for 2.
> > Using Packagings does not work either.
> > Any advice?
> >
> > Thank you
> > --
> > DANIEL
> > REIS*
> > MANAGING PARTNER
> > M:*
> > +351 919 991 307
> > E:*
> > dreis@OpenSourceIntegrators.com [1]
> > A:*
> > Avenida da República 3000, Estoril Office B, 3º Escr.34,
> > 2649-517 Cascais
> >
> >
> >
> >
> > _______________________________________________
> > Mailing-List: https://odoo-community.org/groups/contributors-15 [2]
> > Post to: mailto:contributors@odoo-community.org
> > Unsubscribe: https://odoo-community.org/groups?unsubscribe [3]
> >
> >
> >
> > [1] mailto:dreis@OpenSourceIntegrators.com
> > [2] https://odoo-community.org/groups/contributors-15
> > [3] https://odoo-community.org/groups?unsubscribe
>
> _______________________________________________
> Mailing-List: https://odoo-community.org/groups/contributors-15 [2]
> Post to: mailto:contributors@odoo-community.org
> Unsubscribe: https://odoo-community.org/groups?unsubscribe [3]
>
>
>
> Stefano Consolaro
> www.mymage.it
>
> _______________________________________________
> Mailing-List: https://odoo-community.org/groups/contributors-15 [4]
> Post to: mailto:contributors@odoo-community.org
> Unsubscribe: https://odoo-community.org/groups?unsubscribe [5]
>
>
>
> [1] https://github.com/OCA/stock-logistics-warehouse/pull/1769
> [2] https://odoo-community.org/groups/contributors-15
> [3] https://odoo-community.org/groups?unsubscribe
> [4] https://odoo-community.org/groups/contributors-15
> [5] https://odoo-community.org/groups?unsubscribe
Reference
-
Receiving in the Purchase UoM
byClosingAp Open Source Integrators Europe, LDA, Daniel Reis