first commit
This commit is contained in:
2
modules/carrier_percentage/__init__.py
Normal file
2
modules/carrier_percentage/__init__.py
Normal 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.
|
||||
BIN
modules/carrier_percentage/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
modules/carrier_percentage/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/carrier_percentage/__pycache__/carrier.cpython-311.pyc
Normal file
BIN
modules/carrier_percentage/__pycache__/carrier.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/carrier_percentage/__pycache__/sale.cpython-311.pyc
Normal file
BIN
modules/carrier_percentage/__pycache__/sale.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/carrier_percentage/__pycache__/stock.cpython-311.pyc
Normal file
BIN
modules/carrier_percentage/__pycache__/stock.cpython-311.pyc
Normal file
Binary file not shown.
51
modules/carrier_percentage/carrier.py
Normal file
51
modules/carrier_percentage/carrier.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# 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.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class Carrier(metaclass=PoolMeta):
|
||||
__name__ = 'carrier'
|
||||
percentage = fields.Numeric(
|
||||
"Percentage", digits=(None, 8),
|
||||
states={
|
||||
'invisible': Eval('carrier_cost_method') != 'percentage',
|
||||
},
|
||||
help="The percentage applied on the amount to compute the cost.")
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
selection = ('percentage', 'Percentage')
|
||||
if selection not in cls.carrier_cost_method.selection:
|
||||
cls.carrier_cost_method.selection.append(selection)
|
||||
|
||||
def compute_percentage(self, amount, currency_id):
|
||||
"Compute price based on a percentage of amount"
|
||||
Currency = Pool().get('currency.currency')
|
||||
|
||||
price = amount * self.percentage / Decimal(100)
|
||||
currency = Currency(currency_id)
|
||||
return currency.round(price), currency_id
|
||||
|
||||
def get_sale_price(self):
|
||||
price, currency_id = super().get_sale_price()
|
||||
if self.carrier_cost_method == 'percentage':
|
||||
amount = Transaction().context.get('amount', Decimal(0))
|
||||
currency_id = Transaction().context.get('currency', currency_id)
|
||||
if currency_id is not None:
|
||||
return self.compute_percentage(amount, currency_id)
|
||||
return price, currency_id
|
||||
|
||||
def get_purchase_price(self):
|
||||
price, currency_id = super().get_purchase_price()
|
||||
if self.carrier_cost_method == 'percentage':
|
||||
amount = Transaction().context.get('amount', Decimal(0))
|
||||
currency_id = Transaction().context.get('currency', currency_id)
|
||||
if currency_id is not None:
|
||||
return self.compute_percentage(amount, currency_id)
|
||||
return price, currency_id
|
||||
13
modules/carrier_percentage/carrier.xml
Normal file
13
modules/carrier_percentage/carrier.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="carrier_view_form">
|
||||
<field name="model">carrier</field>
|
||||
<field name="type" eval="None"/>
|
||||
<field name="inherit" ref="carrier.carrier_view_form"/>
|
||||
<field name="name">carrier_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
15
modules/carrier_percentage/locale/bg.po
Normal file
15
modules/carrier_percentage/locale/bg.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Процент"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Процент"
|
||||
15
modules/carrier_percentage/locale/ca.po
Normal file
15
modules/carrier_percentage/locale/ca.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentatge"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "El percentatge aplicat al import per calcular el cost."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentatge"
|
||||
15
modules/carrier_percentage/locale/cs.po
Normal file
15
modules/carrier_percentage/locale/cs.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
17
modules/carrier_percentage/locale/de.po
Normal file
17
modules/carrier_percentage/locale/de.po
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Prozentsatz"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
"Der Prozentsatz der auf den Betrag angewendet wird um die Kosten zu "
|
||||
"errechnen."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Prozentsatz"
|
||||
15
modules/carrier_percentage/locale/es.po
Normal file
15
modules/carrier_percentage/locale/es.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Porcentaje"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "El porcentaje que se aplicará al importe para calcular el coste."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Porcentaje"
|
||||
15
modules/carrier_percentage/locale/es_419.po
Normal file
15
modules/carrier_percentage/locale/es_419.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
15
modules/carrier_percentage/locale/et.po
Normal file
15
modules/carrier_percentage/locale/et.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Protsent"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "Väärtusele kulu arvestamiseks rakendatav protsent"
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Protsent"
|
||||
15
modules/carrier_percentage/locale/fa.po
Normal file
15
modules/carrier_percentage/locale/fa.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "درصد"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "درصد اعمال شده بر مقدار برای محاسبه هزینه."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "درصد"
|
||||
15
modules/carrier_percentage/locale/fi.po
Normal file
15
modules/carrier_percentage/locale/fi.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
15
modules/carrier_percentage/locale/fr.po
Normal file
15
modules/carrier_percentage/locale/fr.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Pourcentage"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "Le pourcentage appliqué sur le montant pour calculer le coût."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Pourcentage"
|
||||
17
modules/carrier_percentage/locale/hu.po
Normal file
17
modules/carrier_percentage/locale/hu.po
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Százalék:"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Százalék:"
|
||||
15
modules/carrier_percentage/locale/id.po
Normal file
15
modules/carrier_percentage/locale/id.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Persentase"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Persentase"
|
||||
15
modules/carrier_percentage/locale/it.po
Normal file
15
modules/carrier_percentage/locale/it.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentuale"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "La percentuale applicata sull'importo per calcolare il costo."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentuale"
|
||||
15
modules/carrier_percentage/locale/lo.po
Normal file
15
modules/carrier_percentage/locale/lo.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "ອັດຕາສ່ວນຮ້ອຍ"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "ອັດຕາສ່ວນຮ້ອຍໄດ້ປັບໃຊ້ກັບມູນຄ່າເພື່ອຄິດໄລ່ລາຄາ"
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "ອັດຕາສ່ວນຮ້ອຍ"
|
||||
15
modules/carrier_percentage/locale/lt.po
Normal file
15
modules/carrier_percentage/locale/lt.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procentas"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procentas"
|
||||
16
modules/carrier_percentage/locale/nl.po
Normal file
16
modules/carrier_percentage/locale/nl.po
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentage"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
"Het percentage dat wordt toegepast op het bedrag om de kosten te berekenen."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Percentage"
|
||||
15
modules/carrier_percentage/locale/pl.po
Normal file
15
modules/carrier_percentage/locale/pl.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procent"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procent"
|
||||
15
modules/carrier_percentage/locale/pt.po
Normal file
15
modules/carrier_percentage/locale/pt.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Porcentagem"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "A porcentagem aplicada à quantidade para calcular o custo."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Porcentagem"
|
||||
15
modules/carrier_percentage/locale/ro.po
Normal file
15
modules/carrier_percentage/locale/ro.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procent"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "Procentul aplicat sumei pentru calculare a costului."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Procent"
|
||||
17
modules/carrier_percentage/locale/ru.po
Normal file
17
modules/carrier_percentage/locale/ru.po
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Процент"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Процент"
|
||||
15
modules/carrier_percentage/locale/sl.po
Normal file
15
modules/carrier_percentage/locale/sl.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "Odstoten"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr "Odstotek, ki se aplicira na znesek za izračun stroška."
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "Odstoten"
|
||||
15
modules/carrier_percentage/locale/tr.po
Normal file
15
modules/carrier_percentage/locale/tr.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
15
modules/carrier_percentage/locale/uk.po
Normal file
15
modules/carrier_percentage/locale/uk.po
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr ""
|
||||
17
modules/carrier_percentage/locale/zh_CN.po
Normal file
17
modules/carrier_percentage/locale/zh_CN.po
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:carrier,percentage:"
|
||||
msgid "Percentage"
|
||||
msgstr "百分比"
|
||||
|
||||
msgctxt "help:carrier,percentage:"
|
||||
msgid "The percentage applied on the amount to compute the cost."
|
||||
msgstr ""
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "selection:carrier,carrier_cost_method:"
|
||||
msgid "Percentage"
|
||||
msgstr "百分比"
|
||||
27
modules/carrier_percentage/sale.py
Normal file
27
modules/carrier_percentage/sale.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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 PoolMeta
|
||||
|
||||
|
||||
class Sale(metaclass=PoolMeta):
|
||||
__name__ = 'sale.sale'
|
||||
|
||||
def _get_carrier_context(self, carrier):
|
||||
context = super()._get_carrier_context(carrier)
|
||||
|
||||
if carrier.carrier_cost_method != 'percentage':
|
||||
return context
|
||||
if not self.currency:
|
||||
return context
|
||||
context = context.copy()
|
||||
amount = 0
|
||||
for line in self.lines or []:
|
||||
if (getattr(line, 'unit_price', None)
|
||||
and (getattr(line, 'quantity') or 0) > 0
|
||||
and not getattr(line, 'shipment_cost', None)):
|
||||
amount += line.unit_price * Decimal(str(line.quantity))
|
||||
context['amount'] = amount
|
||||
context['currency'] = self.currency.id
|
||||
return context
|
||||
60
modules/carrier_percentage/stock.py
Normal file
60
modules/carrier_percentage/stock.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# 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.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
|
||||
def _percentage_amount(lines, company):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
Currency = pool.get('currency.currency')
|
||||
|
||||
amount = 0
|
||||
for line in lines or []:
|
||||
unit_price = getattr(line, 'unit_price', None)
|
||||
currency = getattr(line, 'currency', None)
|
||||
if unit_price is None and isinstance(line.origin, Move):
|
||||
unit_price = line.origin.unit_price
|
||||
currency = line.origin.currency
|
||||
if unit_price is None:
|
||||
unit_price = Decimal(0)
|
||||
currency = None
|
||||
if currency:
|
||||
unit_price = Currency.compute(currency, unit_price,
|
||||
company.currency, round=False)
|
||||
amount += unit_price * Decimal(str(line.quantity or 0))
|
||||
return amount
|
||||
|
||||
|
||||
class ShipmentIn(metaclass=PoolMeta):
|
||||
__name__ = 'stock.shipment.in'
|
||||
|
||||
@fields.depends('carrier', 'incoming_moves', 'company')
|
||||
def _get_carrier_context(self):
|
||||
context = super()._get_carrier_context()
|
||||
if not self.carrier or not self.company:
|
||||
return context
|
||||
if self.carrier.carrier_cost_method != 'percentage':
|
||||
return context
|
||||
context['amount'] = _percentage_amount(
|
||||
self.incoming_moves, self.company)
|
||||
context['currency'] = self.company.currency.id
|
||||
return context
|
||||
|
||||
|
||||
class ShipmentOut(metaclass=PoolMeta):
|
||||
__name__ = 'stock.shipment.out'
|
||||
|
||||
@fields.depends('carrier', 'inventory_moves', 'company')
|
||||
def _get_carrier_context(self):
|
||||
context = super()._get_carrier_context()
|
||||
if not self.carrier or not self.company:
|
||||
return context
|
||||
if self.carrier.carrier_cost_method != 'percentage':
|
||||
return context
|
||||
context['amount'] = _percentage_amount(
|
||||
self.inventory_moves, self.company)
|
||||
context['currency'] = self.company.currency.id
|
||||
return context
|
||||
2
modules/carrier_percentage/tests/__init__.py
Normal file
2
modules/carrier_percentage/tests/__init__.py
Normal 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.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,235 @@
|
||||
=======================================================
|
||||
Carrier Percentage with Purchase Shipment Cost Scenario
|
||||
=======================================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... create_payment_term, set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'carrier_percentage',
|
||||
... 'purchase_shipment_cost',
|
||||
... 'sale_shipment_cost',
|
||||
... ],
|
||||
... create_company, create_chart)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('8')
|
||||
>>> product.save()
|
||||
|
||||
>>> carrier_template = ProductTemplate()
|
||||
>>> carrier_template.name = 'Carrier Product'
|
||||
>>> carrier_template.default_uom = unit
|
||||
>>> carrier_template.type = 'service'
|
||||
>>> carrier_template.salable = True
|
||||
>>> carrier_template.list_price = Decimal('5')
|
||||
>>> carrier_template.account_category = account_category
|
||||
>>> carrier_template.save()
|
||||
>>> carrier_product, = carrier_template.products
|
||||
>>> carrier_product.cost_price = Decimal('3')
|
||||
>>> carrier_product.save()
|
||||
|
||||
Create carrier::
|
||||
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> carrier = Carrier()
|
||||
>>> party = Party(name='Carrier')
|
||||
>>> party.save()
|
||||
>>> carrier.party = party
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.carrier_cost_method = 'percentage'
|
||||
>>> carrier.percentage = Decimal('15')
|
||||
>>> carrier.save()
|
||||
|
||||
Receive a single product line::
|
||||
|
||||
>>> ShipmentIn = Model.get('stock.shipment.in')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> supplier_location, = Location.find([
|
||||
... ('code', '=', 'SUP'),
|
||||
... ])
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.from_location = supplier_location
|
||||
>>> move.to_location = shipment.warehouse.input_location
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 50
|
||||
>>> move.unit_price = Decimal('8')
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment.carrier = carrier
|
||||
>>> shipment.cost_used
|
||||
Decimal('60.0000')
|
||||
>>> assertEqual(shipment.cost_currency_used, company.currency)
|
||||
>>> shipment.click('receive')
|
||||
>>> shipment.state
|
||||
'received'
|
||||
>>> move, = shipment.incoming_moves
|
||||
>>> move.unit_price
|
||||
Decimal('9.2000')
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Sale products with cost on shipment::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.carrier = carrier
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale.invoice_method = 'shipment'
|
||||
>>> sale.shipment_cost_method = 'shipment'
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 5.0
|
||||
>>> sale.click('quote')
|
||||
>>> cost_line = sale.lines[-1]
|
||||
>>> assertEqual(cost_line.product, carrier_product)
|
||||
>>> cost_line.quantity
|
||||
1.0
|
||||
>>> cost_line.amount
|
||||
Decimal('15.00')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('115.00')
|
||||
|
||||
Send products::
|
||||
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
>>> shipment, = sale.shipments
|
||||
>>> assertEqual(shipment.carrier, carrier)
|
||||
>>> shipment.cost_used
|
||||
Decimal('15.0000')
|
||||
>>> shipment.cost_sale_used
|
||||
Decimal('15.0000')
|
||||
>>> assertEqual(shipment.cost_sale_currency_used, company.currency)
|
||||
>>> move, = shipment.inventory_moves
|
||||
>>> move.quantity = 4
|
||||
>>> shipment.cost_used
|
||||
Decimal('12.0000')
|
||||
>>> shipment.cost_sale_used
|
||||
Decimal('12.0000')
|
||||
>>> assertEqual(shipment.cost_sale_currency_used, company.currency)
|
||||
>>> shipment.state
|
||||
'waiting'
|
||||
>>> shipment.click('assign_force')
|
||||
>>> shipment.state
|
||||
'assigned'
|
||||
>>> shipment.click('pick')
|
||||
>>> shipment.state
|
||||
'picked'
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.state
|
||||
'packed'
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
Check customer invoice::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> invoice, = sale.invoices
|
||||
>>> invoice.untaxed_amount
|
||||
Decimal('92.00')
|
||||
|
||||
Sale products with cost on order::
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.carrier = carrier
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale.invoice_method = 'order'
|
||||
>>> sale.shipment_cost_method = 'order'
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 3.0
|
||||
>>> sale.click('quote')
|
||||
>>> cost_line = sale.lines[-1]
|
||||
>>> assertEqual(cost_line.product, carrier_product)
|
||||
>>> cost_line.quantity
|
||||
1.0
|
||||
>>> cost_line.amount
|
||||
Decimal('9.00')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('69.00')
|
||||
|
||||
Check customer shipment::
|
||||
|
||||
>>> shipment, = sale.shipments
|
||||
>>> assertEqual(shipment.carrier, carrier)
|
||||
|
||||
Check customer invoice::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> invoice, = sale.invoices
|
||||
>>> invoice.untaxed_amount
|
||||
Decimal('69.00')
|
||||
58
modules/carrier_percentage/tests/test_module.py
Normal file
58
modules/carrier_percentage/tests/test_module.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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.modules.currency.tests import create_currency
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class CarrierPercentageTestCase(ModuleTestCase):
|
||||
'Test CarrierPercentage module'
|
||||
module = 'carrier_percentage'
|
||||
extras = [
|
||||
'purchase_shipment_cost', 'sale_shipment_cost', 'stock_shipment_cost']
|
||||
|
||||
@with_transaction()
|
||||
def test_compute_percentage(self):
|
||||
'Test compute_percentage'
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Uom = pool.get('product.uom')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Carrier = pool.get('carrier')
|
||||
|
||||
party, = Party.create([{
|
||||
'name': 'Carrier',
|
||||
}])
|
||||
uom, = Uom.search([
|
||||
('name', '=', 'Unit'),
|
||||
])
|
||||
template, = Template.create([{
|
||||
'name': 'Carrier',
|
||||
'default_uom': uom.id,
|
||||
'type': 'service',
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
currency = create_currency('cu1')
|
||||
carrier, = Carrier.create([{
|
||||
'party': party.id,
|
||||
'carrier_product': product.id,
|
||||
'carrier_cost_method': 'percentage',
|
||||
'percentage': Decimal(15),
|
||||
}])
|
||||
for amount, price in [
|
||||
(Decimal(0), Decimal(0)),
|
||||
(Decimal(100), Decimal('15.00')),
|
||||
(Decimal(150), Decimal('22.50')),
|
||||
]:
|
||||
self.assertEqual(
|
||||
carrier.compute_percentage(amount, currency.id),
|
||||
(price, currency.id))
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/carrier_percentage/tests/test_scenario.py
Normal file
8
modules/carrier_percentage/tests/test_scenario.py
Normal 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)
|
||||
26
modules/carrier_percentage/tryton.cfg
Normal file
26
modules/carrier_percentage/tryton.cfg
Normal file
@@ -0,0 +1,26 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
carrier
|
||||
currency
|
||||
ir
|
||||
res
|
||||
extras_depend:
|
||||
purchase_shipment_cost
|
||||
sale_shipment_cost
|
||||
stock_shipment_cost
|
||||
xml:
|
||||
carrier.xml
|
||||
|
||||
[register]
|
||||
model:
|
||||
carrier.Carrier
|
||||
|
||||
[register purchase_shipment_cost]
|
||||
model:
|
||||
stock.ShipmentIn
|
||||
|
||||
[register sale_shipment_cost]
|
||||
model:
|
||||
stock.ShipmentOut
|
||||
sale.Sale
|
||||
11
modules/carrier_percentage/view/carrier_form.xml
Normal file
11
modules/carrier_percentage/view/carrier_form.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='carrier_cost_method']" position="after">
|
||||
<newline/>
|
||||
<label name="percentage"/>
|
||||
<field name="percentage"/>
|
||||
<newline/>
|
||||
</xpath>
|
||||
</data>
|
||||
Reference in New Issue
Block a user