first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,14 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import PoolMeta
class Carrier(metaclass=PoolMeta):
__name__ = 'carrier'
@classmethod
def __setup__(cls):
super().__setup__()
cls.shipment_cost_allocation_method.selection.append(
('weight', "By Weight"))

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Per pes"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Nach Gewicht"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Por peso"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Par poids"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Per peso"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "Op gewicht"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,8 @@
#
#, fuzzy
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr "După Greutate"

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,7 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:carrier,shipment_cost_allocation_method:"
msgid "By Weight"
msgstr ""

View File

@@ -0,0 +1,37 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from decimal import Decimal
from trytond.pool import Pool, PoolMeta
class ShipmentCostMixinWeight:
__slots__ = ()
def _get_allocation_shipment_cost_factors_by_weight(self):
pool = Pool()
Move = pool.get('stock.move')
if getattr(Move, 'internal_weight', None):
sum_weight = Decimal(0)
weights = {}
for move in self.shipment_cost_moves:
weight = Decimal(str(move.internal_weight or 0))
weights[move.id] = weight
sum_weight += weight
if sum_weight:
factors = {}
for move in self.shipment_cost_moves:
factors[move.id] = weights[move.id] / sum_weight
return factors
return self._get_allocation_shipment_cost_factors_by_cost()
class ShipmentOut(ShipmentCostMixinWeight, metaclass=PoolMeta):
__name__ = 'stock.shipment.out'
class ShipmentOutReturn(
ShipmentCostMixinWeight, metaclass=PoolMeta):
__name__ = 'stock.shipment.out.return'

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,122 @@
===================================
Stock Shipment Cost Weight Scenario
===================================
Imports::
>>> from decimal import Decimal
>>> from unittest.mock import patch
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.modules.stock_shipment_cost.stock import ShipmentCostMixin
>>> from trytond.tests.tools import activate_modules
Patch _get_shipment_cost::
>>> mock = patch.object(
... ShipmentCostMixin, '_get_shipment_cost',
... return_value=Decimal('8')).start()
Activate modules::
>>> config = activate_modules('stock_shipment_cost_weight', create_company)
>>> Carrier = Model.get('carrier')
>>> Location = Model.get('stock.location')
>>> Party = Model.get('party.party')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUom = Model.get('product.uom')
>>> Shipment = Model.get('stock.shipment.out')
Get currency::
>>> currency = get_currency()
Create customer::
>>> customer = Party(name='Customer')
>>> customer.save()
Create products::
>>> unit, = ProductUom.find([('name', '=', "Unit")])
>>> gram, = ProductUom.find([('name', '=', "Gram")])
>>> template = ProductTemplate()
>>> template.name = "Product1"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.weight = 500
>>> template.weight_uom = gram
>>> template.save()
>>> product1, = template.products
>>> product1.cost_price = Decimal('10.0000')
>>> product1.save()
>>> template = ProductTemplate()
>>> template.name = "Product2"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.weight = 250
>>> template.weight_uom = gram
>>> template.save()
>>> product2, = template.products
>>> product2.cost_price = Decimal('20.0000')
>>> product2.save()
>>> carrier_template = ProductTemplate()
>>> carrier_template.name = "Carrier Product"
>>> carrier_template.default_uom = unit
>>> carrier_template.type = 'service'
>>> carrier_template.save()
>>> carrier_product, = carrier_template.products
Create carrier::
>>> carrier = Carrier()
>>> carrier.party = Party(name="Carrier")
>>> carrier.party.save()
>>> carrier.carrier_product = carrier_product
>>> carrier.shipment_cost_allocation_method = 'weight'
>>> carrier.save()
Get stock locations::
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> output_loc, = Location.find([('code', '=', 'OUT')])
Create a customer shipment::
>>> shipment = Shipment()
>>> shipment.customer = customer
>>> shipment.carrier = carrier
>>> move = shipment.outgoing_moves.new()
>>> move.product = product1
>>> move.quantity = 1
>>> move.from_location = output_loc
>>> move.to_location = customer_loc
>>> move.unit_price = Decimal('30')
>>> move.currency = currency
>>> move = shipment.outgoing_moves.new()
>>> move.product = product2
>>> move.quantity = 2
>>> move.from_location = output_loc
>>> move.to_location = customer_loc
>>> move.unit_price = Decimal('40')
>>> move.currency = currency
>>> shipment.click('wait')
>>> shipment.click('assign_force')
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('do')
>>> shipment.state
'done'
Check move costs::
>>> sorted([
... (m.cost_price, m.shipment_out_cost_price)
... for m in shipment.outgoing_moves])
[(Decimal('10.0000'), Decimal('4.0000')), (Decimal('20.0000'), Decimal('2.0000'))]

View File

@@ -0,0 +1,12 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase
class StockShipmentCostWeightTestCase(ModuleTestCase):
'Test Stock Shipment Cost Weight module'
module = 'stock_shipment_cost_weight'
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)

View File

@@ -0,0 +1,13 @@
[tryton]
version=7.8.0
depends:
carrier
ir
stock_shipment_cost
stock_shipment_measurements
[register]
model:
carrier.Carrier
stock.ShipmentOut
stock.ShipmentOutReturn